Announcement

Collapse
No announcement yet.

OT time clock alarm/horn ideas

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #46
    Just moving this to the top again while waiting for that widget to arrive at Mcgyver's place..

    Comment


    • #47
      ...bumping this to the top.

      Comment


      • #48
        Still nothing.....
        in Toronto Ontario - where are you?

        Comment


        • #49
          Good job, Artful,
          Did you do it in dos script or in VisualBasic?

          A Time clock program:
          On linux I am a fan of shell scripting in bash.
          I learned programming starting in 1969 so my methods are not politically correct to the young guys.
          Bash is an ancient scripting method but still powerful.

          I process color film here manually in the darkroom which is a 960 second tedious job,
          involving pouring five chemical solutions into the tank at certain time intervals, and inverting the tank every 30 second

          So I have a time clock program in bash, which displays which chemical to pour.
          At present it plays tones through the stereo speakers at each interval.

          On the to-do list, I have a little gear motor to make an automatic holder for the tank, to do the 30 sec inversions .
          I could probably use the same usb relay you selected.

          Here is the executable script which is blocked for download but the text can be copied off the browser,
          for anyone interested in the scripting language ( it almost reads like english) or making a process time clock.
          https://app.box.com/s/rxgs2wv29u87bwbggzanvuk7xyapslo2

          Comment


          • #50
            Originally posted by wombat2go View Post
            Good job, Artful,
            Did you do it in dos script or in VisualBasic?
            Hi Wombat, I started off intending to write a Dos batch file that anyone could use on just about about Micro$oft computer but I ran into a snag. I discovered the relay unit requires a null character to be sent to it and I could not find a way to do that from a Dos batch without phutzing about with dummy files and such like.

            I wrote the program in Pascal using Lazarus Free Pascal, I would have liked to have used Delphi but I no longer have an install for that and Lazarus seems very good once I learned the few little differences in the IDE.

            The program interprets the command line parameters and sends the open or close sequence to the relay unit, once it gets to the end of the command line the program terminates.

            For a job like the shop horn the command line will require only the port number and the toot argument which will be all that is required to be put in to the Task Scheduler.

            The USB relay is easy to use but almost impossible to find information on but I did find it eventually and my two relays do work as expected. If you want to use one be aware that it requires a null byte in the middle of the command string.

            The serial port configuration is 9600,N,8,1
            Command sequence to close relay is hex A0,01,01,A2
            and to open the relay the sequence is hex A0,01,00,A1

            John
            Last edited by The Artful Bodger; 09-27-2017, 03:16 PM.

            Comment


            • #51
              Originally posted by Mcgyver View Post
              Still nothing.....
              The boat must have come to NZ first!

              BTW, I noticed mine had been posted from Singapore.

              Comment


              • #52
                Bump...........................just bringing this to the top again.

                Comment


                • #53
                  Originally posted by The Artful Bodger View Post
                  Bump...........................just bringing this to the top again.
                  Why? It will still be here later....

                  Comment


                  • #54
                    Originally posted by elf View Post
                    Why? It will still be here later....
                    Yes it will but I want to keep it near the top if for no other reason than someone else may be interested is this and having another thread started on the same subject could be quite confusing.

                    Comment


                    • #55
                      Originally posted by The Artful Bodger View Post
                      Yes it will but I want to keep it near the top if for no other reason than someone else may be interested is this and having another thread started on the same subject could be quite confusing.

                      Two OT threads about horns? Good move bringing this to the top and bumping something on topic. We definitely don't need two OT horn threads..

                      Comment


                      • #56
                        well its OT but no too OT....horn is for a metal shop, and I will make an electrical box for it.

                        Nothing yet John, don't worry I won't forget .
                        in Toronto Ontario - where are you?

                        Comment


                        • #57
                          Hi Mcgyver, that man on the rickshaw should be drawing close to your town soon. Have you looked the Task Scheduler and how to set it up?

                          The program has been further refined during this wait period and is now somewhat simpler to use than previously described.

                          John

                          Comment


                          • #58
                            Originally posted by 3 Phase Lightbulb View Post
                            Two OT threads about horns? Good move bringing this to the top and bumping something on topic. We definitely don't need two OT horn threads..
                            I was somewhat surprised to find these little devices as I can see them be useful for various time related tasks, for example I could use mine to turn my compressor off in the evening and not on again to morning but fortunately I have managed to find the elusive leak and I no longer hear the little compressor out in the garden shed in the middle of the night!

                            I was also somewhat surprised how difficult it was to get the information how to use the USB relay device and when I did find the information I was again surprised at how awkward the control signal is to generate. But I have solved those issues and the information is now available to anyone on this site who is thinking of using these devices.

                            John

                            Comment


                            • #59
                              I just caught up with this thread and it might be something I might find useful. I have a working copy of Borland Delphi 4 Pro and recently I have also been working with Lazarus and Free Pascal. Could you post the source code?

                              I found a two channel USB relay on our favorite cheap Chinese source Banggood, about $10:
                              https://www.banggood.com/5V-2-Channe...l?rmmds=search (sold out currently)

                              I also have designed an SCR trigger board for high power applications (up to 480 VAC and 500 amps) but also works with smaller SCRs connected in anti-parallel as an AC switch. It is intended to provide adjustable initial phase angle for driving inductive loads, but it also could be programmed for a variable phase angle control for a motor, heater, or lighting. It has two isolated gate drives that could be used independently. It has a serial port which can be RS-232 but I have also used it with a Bluetooth module so as to control it with my PC and a simple terminal program. It can accept commands such as "P40" for 40 degree phase angle, "T60" for 60 cycles (one second) on time, "I" to initiate, and "S" to stop. It uses about $45 worth of components, and the PCB was $25. I have some surplus 90A 600V SCR modules that work well with this - you could drive a really loud horn with 240V and 50A - 12 kW!

                              I have a few blank boards from an earlier design and I can supply documentation if you have interest and need for such a device.

                              Here is one of the boards. This one does not have the RS-232 chip but I have modified it for a Bluetooth module by adding a SIP socket and four wires for GND, +5V, RXD, and TXD.

                              http://pauleschoen.com/pix/PM08_P76_P54.png
                              Paul , P S Technology, Inc. and MrTibbs
                              USA Maryland 21030

                              Comment


                              • #60
                                Originally posted by PStechPaul View Post
                                I just caught up with this thread and it might be something I might find useful. I have a working copy of Borland Delphi 4 Pro and recently I have also been working with Lazarus and Free Pascal. Could you post the source code?
                                Sure...

                                Program hoot;
                                {



                                }
                                uses
                                serial, crt, SysUtils,registry,classes;

                                VAR
                                serialhandle : LongInt;
                                ComPortName : String;
                                s,tmpstr,txt : String;
                                ComOut,ComIn : String;
                                ComPortNr : integer;
                                writecount : integer;
                                status : LongInt;

                                BitsPerSec : LongInt;
                                ByteSize : Integer;
                                Parity : TParityType; { TParityType = (NoneParity, OddParity, EvenParity); }
                                StopBits : Integer;
                                Flags : TSerialFlags; { TSerialFlags = set of (RtsCtsFlowControl); }


                                ErrorCode : Integer;



                                function GetSerialPortNamesExt: string;
                                var
                                reg : TRegistry;
                                l,v : TStringList;
                                n : integer;
                                pn,fn: string;

                                function findFriendlyName(key: string; port: string): string;
                                var
                                r : TRegistry;
                                k : TStringList;
                                i : Integer;
                                ck: string;
                                rs: string;
                                begin
                                r := TRegistry.Create;
                                k := TStringList.Create;

                                r.RootKey := HKEY_LOCAL_MACHINE;
                                r.OpenKeyReadOnly(key);
                                r.GetKeyNames(k);
                                r.CloseKey;

                                try
                                for i := 0 to k.Count - 1 do
                                begin
                                ck := key + k[i] + '\'; // current key
                                // looking for "PortName" stringvalue in "Device Parameters" subkey
                                if r.OpenKeyReadOnly(ck + 'Device Parameters') then
                                begin
                                if r.ReadString('PortName') = port then
                                begin
                                //Memo1.Lines.Add('--> ' + ck);
                                r.CloseKey;
                                r.OpenKeyReadOnly(ck);
                                rs := r.ReadString('FriendlyName');
                                Break;
                                end // if r.ReadString('PortName') = port ...
                                end // if r.OpenKeyReadOnly(ck + 'Device Parameters') ...
                                // keep looking on subkeys for "PortName"
                                else // if not r.OpenKeyReadOnly(ck + 'Device Parameters') ...
                                begin
                                if r.OpenKeyReadOnly(ck) and r.HasSubKeys then
                                begin
                                rs := findFriendlyName(ck, port);
                                if rs <> '' then Break;
                                end; // if not (r.OpenKeyReadOnly(ck) and r.HasSubKeys) ...
                                end; // if not r.OpenKeyReadOnly(ck + 'Device Parameters') ...
                                end; // for i := 0 to k.Count - 1 ...
                                result := rs;
                                finally
                                r.Free;
                                k.Free;
                                end; // try ...
                                end; // function findFriendlyName ...

                                begin
                                v := TStringList.Create;
                                l := TStringList.Create;
                                reg := TRegistry.Create;
                                Result := '';

                                try
                                reg.RootKey := HKEY_LOCAL_MACHINE;
                                if reg.OpenKeyReadOnly('HARDWARE\DEVICEMAP\SERIALCOMM ') then
                                begin
                                reg.GetValueNames(l);

                                for n := 0 to l.Count - 1 do
                                begin
                                pn := reg.ReadString(l[n]);
                                fn := findFriendlyName('\System\CurrentControlSet\Enum\' , pn);
                                if Pos('CH340',fn)>0 then break; // found a USB relay port
                                end; // for n := 0 to l.Count - 1 ...


                                delete(pn,1,3); // get com number only

                                Result := pn;
                                end; // if reg.OpenKeyReadOnly('HARDWARE\DEVICEMAP\SERIALCOMM ') ...
                                finally
                                reg.Free;
                                v.Free;
                                end; // try ...
                                end;




                                procedure CloseRelay(Close:boolean);
                                begin

                                serialhandle := SerOpen(ComPortName);
                                Flags:= [ ]; // None
                                SerSetParams(serialhandle,9600,8,NoneParity,1,Flag s);
                                s:=txt; // use the input text
                                if close then
                                begin
                                s:=chr($A0)+chr($01)+chr($01)+chr($A2);
                                writeln('Relay closed '+ComPortName);
                                end
                                else
                                begin
                                s:=chr($A0)+chr($01)+chr($00)+chr($A1);
                                writeln('Relay open '+ComPortName);
                                end;
                                writecount := length(s);
                                status := SerWrite(serialhandle, s[1], writecount );
                                sleep(500);
                                SerSync(serialhandle); { flush out any remaining before closure }

                                SerFlushOutput(serialhandle); { discard any remaining output }

                                SerClose(serialhandle);
                                end;

                                procedure ShortToot; //default 500milisec toof
                                begin
                                CloseRelay(true);
                                sleep(500);
                                CloseRelay(false);
                                end ;

                                procedure ReadCMDArgs;
                                var n,tt,ll, argcount,repeatcount :integer;
                                var argstr:String;

                                var portnum:string;
                                begin
                                argcount:=paramcount;
                                if Argcount=0 then /// no paremeter so do a single toot
                                begin
                                ShortToot;
                                end;

                                n:=1;
                                repeatcount:=0;
                                while n<=argcount do
                                begin

                                argstr:=ParamStr(n);


                                case argstr[1] Of

                                'w' : begin
                                if argstr[2]=':' then
                                begin
                                Delete(argstr,1,2);
                                tt:=StrToInt(argstr);
                                sleep(tt*500);
                                end;
                                end;

                                't' : begin //short toot
                                if argstr[2]=':' then
                                begin
                                Delete(argstr,1,2);
                                tt:=StrToInt(argstr);
                                CloseRelay(true);
                                sleep(tt*500);
                                CloseRelay(false);
                                end
                                else
                                ShortToot;

                                end;


                                'p' :
                                begin //SetPortNumber
                                portnum:=argstr[3];
                                if length(argstr)>3 then portnum:=portnum+argstr[4];
                                ComPortName:= 'COM'+portnum;
                                if argcount=1 then ShortToot;
                                end;

                                'c' : begin
                                CloseRelay(true);
                                end;

                                'o' : begin
                                CloseRelay(false);
                                end;
                                'r' : begin //repeat
                                if (argstr[2]=':') then
                                begin
                                if (repeatcount=0) then
                                begin//test if already repeating
                                Delete(argstr,1,2);
                                repeatcount:=StrToInt(argstr);
                                n:=0;
                                end
                                else
                                begin
                                repeatcount:=repeatcount-1;
                                if repeatcount>0 then n:=0; //read CMD args again
                                end;
                                end;
                                end;
                                end;
                                n:=n+1;
                                end;

                                end;




                                BEGIN

                                //Search registry for a COM port
                                ComPortName:= ( GetSerialPortNamesExt);
                                ComPortName:= 'COM'+ComPortName;
                                writeln('ComPortName = '+comportname);
                                tmpstr:='';
                                txt:='';

                                ReadCmdArgs;

                                end.


                                I did that in Lazarus Free Pascal and I am sorry it is not so tidy.

                                Comment

                                Working...
                                X