Announcement

Collapse
No announcement yet.

OT time clock alarm/horn ideas

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

  • #61
    Thanks. Using [ code ] tags would have helped, but that's OK. I loaded it in Lazarus, and it built and ran (after removing a space in the word "Flags" in the following function:
    Code:
    procedure CloseRelay(Close:boolean);
    begin
    
    serialhandle := SerOpen(ComPortName);
    Flags:= [ ]; // None
    SerSetParams(serialhandle,9600,8,NoneParity,1,Flags);
    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;
    Lazarus looks like this:
    http://pauleschoen.com/pix/PM08_P76_P54.png
    Paul , P S Technology, Inc. and MrTibbs
    USA Maryland 21030

    Comment


    • #62
      Yeah, it is a bit rough. With your run it appears it did not find a USB serial relay unit but it carried on and went through the motions of closing and opening an imaginary relay.

      I will write more details tomorrow..

      Comment


      • #63
        I ran it from the IDE with no command line parameters, and put a breakpoint at the end to show the "DOS" window. I had expected it to show the usage of the command line, but of course this is just a "quick and dirty" solution without the usual "bells and whistles", although it does have a "horn" that "gives a hoot"

        I didn't know Lazarus had a built in "TSerial" component "uses serial". Here is a description of various hardware access libraries:

        http://wiki.freepascal.org/Hardware_Access

        I have been using the "TLazSerial" component by Jurassic Pork, which also uses the "Synaser" library:

        https://github.com/JurassicPork/TLaz...3ee31f98a6b3a2
        http://pauleschoen.com/pix/PM08_P76_P54.png
        Paul , P S Technology, Inc. and MrTibbs
        USA Maryland 21030

        Comment


        • #64
          I have used Jurassic Pork but the built in library was enough to do the job and with a command line application there was no need for visible components as I am assuming Mcgyver does not want windows popping up on the screen when the hooter goes.

          Somewhere, possibly in the hardware access library, I found the routine to search for the USBSerial port.

          The command line parameters are now:=

          NOTE. In the most simple case where it is required to sound the shop horn for half a second at a particular time the system I recommend is to run the simple command 'Hoot' at the required time using Windows Task Scheduler.

          NOTE. Command parameters will be executed in the order they are found on the command line. Command parameters may be repeated and the entire line may be repeated.
          The application will close when it reaches the end of the command parameters except in the case of the Repeat command.

          The Port parameter...
          At startup the program looks for a USB Serial Relay port and if it does not find one there is no port set. However a port can be set manually using the argument p:n where n is the port number of the USB Serial Relay you want to use which is not really much use if you only have one USB Serial Relay as the earlier routine should have found it.
          Note:Numbering of USB devices may change for various reasons outside the operators direct control therefore it is advised to only use the Port parameter when using multiple USB Relay ports!

          But in the case where you have two USB Serial Relays (for example one relay unit to control the shop horn and another to turn on the coffee machine) in which case you must specify which port you want operated and this is especially important if you want to use the 'r' Repeat function. I will give an example of this...

          The Toot parameter
          The Toot 't' parameter alone closes the relay for 500milliseconds (half a second) but may be closed for longer by adding a time value (in half seconds) for example t:10 would close the relay for 5 seconds.

          The Wait parameter
          The Wait 'w' parameter introduces a delay in the handling of the command line arguments and the time value is again in half seconds. For example w:10 would give a 5 second delay. I do not know the maximum wait duration but I expect it is in the region of nine hours.

          The Close parameter
          The Close 'c' parameter closes the relay. The relay will stay closed until the next command to open the relay or the computer is turned off or the USB removed from the computer.
          Note: The Close parameter does not have a time value.

          The Open parameter
          The Open 'o' parameter opens the relay.

          The Repeat paramenter
          The Repeat 'r' parameter must be the last parameter in the command and will cause the parameter commands to be repeated. The repeat command must have a qualifer of the number of times to be repeated. For example r:2 will cause the commands to be actioned three times.

          Defaults:-

          No parameters
          If there are no command parameters the program will close the relay for half a second using the first USBRelay port it found and if not a USB Relay port the command will be ineffective.


          Toot, if there is no duration specified the toot command will close the relay for half a second.


          Example command lines:
          Hoot
          The relay on the first USB relay port found will be closed for half a second then the program will terminate.

          Hoot t
          As above but using a t (Toot) command.

          Hoot t w:2 t:6
          The relay will close for half a second then wait for 1 second and close again for 3 seconds.

          Hoot t w:2 t:6 w:10 r:1
          As above then repeat after a 5 second interval.

          Hoot c
          The relay will close and the application will terminate.

          Hoot o
          The relay will open and the application will terminate.


          Multiple USB Relay units
          When using multiple USB Relay units the Com Port number of each port must be in the command line. For example

          Hoot p:8 c p:9 c
          Will close the relay on the USB Serial unit on Com Port 8 and also on the relay unit on Com Port 9 then the program will terminate.

          ....and so on.
          Last edited by The Artful Bodger; 10-05-2017, 08:21 PM.

          Comment


          • #65
            Hi John - good news, the relays arrived (plural in case I let the smoke out of one)

            Coincidentally I put a power supply together over the weekend, so should be close to getting this going
            in Toronto Ontario - where are you?

            Comment


            • #66
              Hi Mcgyver, thats good. I have put the file on my drop box with this link https://www.dropbox.com/s/tpavd1gmjghn848/Hoot.dat?dl=0

              Hopefully it will allow you to download a .DAT file without objection and you can rename to .EXE.

              Note, with this version all you have to do is run it from the command line and it will find the usb relay and do a single toot before closing the program.

              John

              Comment


              • #67
                Hi John,

                i had a chance to work on this today - the program runs perfectly and I think the way you have organized it with switches/parameters and the use of MS scheduler is fantastic. Nice work and thanks again.

                Thwarting success though is getting the box to recognize the USB device. It can't find a suitable driver - windows 7. I see it listed as a USB device with the little yellow caution triangle under "other devices" Searching around the web, there is something about apparently the manufacturer doesn't always get the voltage right for USB standard so they're not recognized, and a workaround is a hub. I'll try that
                in Toronto Ontario - where are you?

                Comment


                • #68
                  Thanks for the update and I hope you can get the device to work.

                  I didn't ask but does your box have a real com port on it? If it does we could always use that as a fallback but you would need a simple transistor circuit to drive a small relay from the modem control lines, hopefully you wont have to do that especially having waited all this time for the USB widgets to be delivered.

                  john
                  Last edited by The Artful Bodger; 10-13-2017, 02:41 PM.

                  Comment


                  • #69
                    I had a look around and I think this is where to find the driver you need...http://www.wch.cn/download/CH341SER_EXE.html

                    I could send you my driver file but it is 64bit version.

                    John

                    Comment


                    • #70
                      Originally posted by The Artful Bodger View Post
                      I had a look around and I think this is where to find the driver you need...http://www.wch.cn/download/CH341SER_EXE.html

                      I could send you my driver file but it is 64bit version.

                      John
                      eureka! bit of old speaker wire and I'm good to go for Monday

                      i don't know how you found that driver but it worked. Its neat product, but they make it really really hard to find what you need to use. The box at work will likely be w10 or XP....we'll see if it works there.
                      in Toronto Ontario - where are you?

                      Comment


                      • #71
                        Thats good!

                        Yes they do make it hard to find information on their product especially as they do not exactly advertise the makers name. In fact I thought I would never find it until I looked at the details of the 64bit driver W10 had used and right there it says the driver was from wch.cn.

                        Comment


                        • #72
                          Mcgyver, how did the system work in practice?

                          Comment


                          • #73
                            Rube would be proud!
                            Paul A.
                            SE Texas

                            And if you look REAL close at an analog signal,
                            You will find that it has discrete steps.

                            Comment


                            • #74
                              Originally posted by The Artful Bodger View Post
                              Mcgyver, how did the system work in practice?
                              testing at home, works perfectly, I plan on installing it tomorrow. I did remember to take it in, so made it that far, but have been running around and there hasn't been a time when the plant manager and I have both been there for a week.
                              in Toronto Ontario - where are you?

                              Comment


                              • #75
                                Originally posted by Paul Alciatore View Post
                                Rube would be proud!
                                'splain please?

                                Comment

                                Working...
                                X