Sending RS232 to PAC

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by richy, Jan 23, 2006.

  1. richy

    richy

    Joined:
    Aug 8, 2004
    Messages:
    88
    Likes Received:
    0
    Location:
    VIC
    Hi I'm trying to send a RS232 command to a PAC

    I've confirmed the Command, by sending it to a standard PC-Int. This works fine.

    However, sending it to a PAC does not work ...

    Do I need to initialize the PAC so its RS232 ports are open ??
    if So how do I do this, it does not makes sense via the logic programming, as it requires me to set a serial port num, and a com port num.

    Can one of the CIS gurus shed some light on this.

    FYI
    the command I am sending, was derrived using the "CBUS-PUBREL" dosument, as I mentioned it works ok for sending RS232 to the PC-Int. Is the protocol different for the PAC ??

    Come to think of it:-
    I will also require the PAC to send RS232 commands, I will have the same delima in the logic programming. Do I need to open/close serial ports on the PAC, if so, how do I write the command.
     
    richy, Jan 23, 2006
    #1
    1. Advertisements

  2. richy

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    The PAC won't act as a PCI and a PAC at the same time.
     
    rhamer, Jan 23, 2006
    #2
    1. Advertisements

  3. richy

    richy

    Joined:
    Aug 8, 2004
    Messages:
    88
    Likes Received:
    0
    Location:
    VIC
    Hi,
    When I said I tested it on a PC-Int, I physically meant a seperate PC-Int, I was not using the PAC in PC-INT mode (didnt know it could be used as a PC-INT, to be honest).

    So, I'm not sure I get what your saying, correct me if I'm wrong. But are you stating, that Once the PAC is running on the Network with your logic in place, the RS232 ports provided, are usless ???

    Just want to clear that up, before we go on to clearing up how to talk to a PAC via RS232 ...
     
    richy, Jan 23, 2006
    #3
  4. richy

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    your getting to the end of my knowledge on the PAC, however you said you confirmed a command by sending it to a PCI first.

    You can't just send a command derived from the Public Release Protocol to the PAC when it is running as a PAC and not a PCI. It has no methods for receiving and decoding what you are sending. If you wanted to send the same format commands you would have to write your own routines that ran inside the PAC that parse and act on the commands you have sent. So there is no PAC serial protocol, you would have to invent your own.

    I think it's time a PAC expert jumped in here, and confirmed my statements, but I'm pretty sure I'm right.

    Perhaps if you explained the scenario, we might be able to offer an alternative.

    Cheers
     
    rhamer, Jan 23, 2006
    #4
  5. richy

    richy

    Joined:
    Aug 8, 2004
    Messages:
    88
    Likes Received:
    0
    Location:
    VIC
    Ok, I'll explain the Purpose ...

    This is were the problem spawns from.

    As many people know, devices that come out with RS232 control, usually only come out with one port. e.g. AMPS, DVD Players, Projectors etc.. etc...

    I would like to integrate to these device, from :-
    a)My C-Bus network ( which should be viable from a PAC or my PC running HomeGate)
    b)My RTI control Device
    c)Really any third party device that can send RS232. !!!

    Here is the issue, If I connect my RTI to the Device, I want to control, then C-bus can't connect to them.
    Therefore my idea was to have my RTI device ( or any Device wanting to talk via RS232 for that matter) connected to my C-Bus network, via a PAC, or a PC-INT.
    Then have a cross reference table in logic for all my RS232 Codes, these codes could then be sent via the PAC.
    I choose the PAC, becuase I could then add as many PAC's as needed to interface to all my RS232 devices that I wish to control.

    So in theory the C-Bus netowrk acts as a conduit for all my RS232 commands, this gives me the ability to control RS232 devices from homegate, key Inputs etc.. etc.., or Remote devices or any device that spits out RS232, as long as it is connected to C-bus, and I have programmed its codes.

    So Once again back to the PAC.
    Ok, Recieving RS232, as you have explained, needs to be done by Opening the port, then writing code to read the port, and react accordingly. Though this sucks, can the CIS legends please confirm ... and if so, is there any code examples ... ??

    Also, in my travels today, I have found its just easier to send RS232 commands directly to a PC-INT, since these are cheaper than a PAC, that is defeinetly the way to go.

    But, PC-INT can't be asked to send RS232, so back to the PAC.

    The deffinitive question is. How to setup a PAC to send RS232 ???
    Lets do this by example:-
    Lets say the PAC is connected to a DenonAVR3805
    its going to send the RS232 string to power the unit on, this is actually
    PWON<cr>
    We want to trigger this command (from within C-bus, from a Group Address)
    Lets say the group address is 0x21. and its in the Lighting App, 0x38.

    So when the address 0x21 comes on, the ASCII string PWON<cr> gets spit out on serial port one of the PAC controller.

    How is it done ????

    This is my understanding, from todays travels.

    {Initialize the string for Power On}
    PowerOn := 'PWON13';
    if GetLightingState(21) then
    begin
    {Initialize the PAC port}
    OpenSerial(1, 1, 9600, 8, 1, 0, 0);
    WriteSerial(1, PowerOn);
    end;

    Don't know if this is correct, comments anyone.

    Also, I would not want this code, to loop for ever, but enabled whenever group address 0x21 becomes - that I dont know how to do ... ?? can anyone help ...

    That should cover evrything ... let me know if I need to expand on anything, if someone aint on the same page ...
     
    richy, Jan 23, 2006
    #5
  6. richy

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    I understand in principle what you want to do, and although possible, it seems like a very expensive way to control a device. i.e 1 PAC per device.

    I'm sorry but I can't help you with the exact code systax, as I have never programmed one, again someone else needs to chime in here.

    I'm also thinking that the group address idea to turn the power on/off would work, but what about other functions like volume and mode selection? and when you get a few devices you will quickly run out of group addresses.

    May I suggest you have a look at this www.charmedquark,com

    This will do all that you have spoken about and much more, for the cost of less than 1 PAC. You can also check out other users (like me) on their forum at http://charmedquark.com/phpBB2/index.php and if they don't have a driver to control your particular hardware (which they do for the Denon) then you can write your own using one of 2 inbuilt programming languages.

    Cheers

    Rohan
     
    rhamer, Jan 23, 2006
    #6
  7. richy

    richy

    Joined:
    Aug 8, 2004
    Messages:
    88
    Likes Received:
    0
    Location:
    VIC
    Ok,

    Had a quick look at http://www.charmedquark.com/, looks good, make for good reading after I figure out the PAC.

    That would be one PAC per two devices.
    I'm trying to figure this out, for applications, that are not running a PC in the project.

    Cheers...
     
    richy, Jan 23, 2006
    #7
  8. richy

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    rhamer, Jan 23, 2006
    #8
  9. richy

    richy

    Joined:
    Aug 8, 2004
    Messages:
    88
    Likes Received:
    0
    Location:
    VIC
    Yeah, I have already printed out that Serial code, but its no help, the Serial code looks as if it was written for a HomeGate Solution. I can't see it working from a PAC.

    i.e. OpenSerial(2, 2, 9600, 8, 1, 0, 0);
    see the second two, actually represents the COM port to open, yet the PAC does not have COM ports like on a PC, so you see something is a miss ...
    Oh, and if you set that to = 1, it compiles ok, but you can't run it, comes up with a huge error (will it only run inside the PAC, I dont know, once again need some input here)

    The USB being unplugged may be a good, suggestion, but I'd like that confirmed.

    I'll just wait for the CIS guys to jump, on ... hopefully they can shed some light.

    Hope I have not been to pushy, or this topic aint been too boring ...


    Cheers

    PS: I'd like to get some momentum on this topic, as this does open many more doors for C-bus ...
     
    richy, Jan 23, 2006
    #9
  10. richy

    alexm

    Joined:
    Aug 15, 2005
    Messages:
    27
    Likes Received:
    1
    Location:
    Wellington
    Hey

    This may seem a stupid question but ill ask it anyway...

    Have you connected the extra power supply to the PAC? as it needs an extra 5v for the rs232 to work. I did not know this myself when first using the PAC, I had to drive myself to read the instructions :eek:

    Heres how to get the PAC or to use the rs232 ports
    first in the initialisation part you must open the desired comm port with the below command :

    OpenSerial(1, 1, 19200, 8, 1, 0, 0); // SerialPortIndex, COMPortNo, BaudRate, DataBits, StopBits, FlowControl, Parity

    The above snippet of code would open up SerialPort 1 (physical), and Comm port 1 (Logical) at a baud of 19200, 8 databits, 1 stopbit, no flow control and no parity (Note with the PAC you can only use Serial port 1 or 2 )

    Now that the comm port is open you can then write some code that reads data that gets sent to the comm port as below:

    str := '';
    repeat
    ReadSerial(1, str, #247);{ #247 is the end of string character }
    if str <> '' then
    begin
    // do something with the str variable
    end;
    until str = '';

    which reads a command from the serial port as recieved.

    And then to write to the serial port you can use the following command:

    WriteSerial(1, 'hello');

    which sends the string hello down the serial port

    Note: this is all from the help file in the PICED program, so if you want more detail refer to that or ask away


    Alex
     
    Last edited by a moderator: Jan 23, 2006
    alexm, Jan 23, 2006
    #10
  11. richy

    Matty

    Joined:
    Oct 15, 2004
    Messages:
    131
    Likes Received:
    0
    PAC programming

    The PAC unit features 2 RS232 ports. This allows using one PAC to control any 2 RS232 devices from the one unit. These ports are not the same as the RS232 port on the PCI. The PCI requires the C-Bus protocol whereas the PAC unit will only respond in the manner it is programmed to respond.

    The USB connection on the PAC has 2 functions. The main function is for programming, the other is for operating as a USB PCI. When using the unit as a USB PCI the logic engine inside the unit will not be running.

    The serial code (as with all the code) is written to be compatible between Homegate, Schedule Plus and PICED (minus a few features in when using CTC, PAC).

    For the RS232 ports to operate they need to source some power from somewhere. This can either be taken from the 24VAC input located on the side of the PAC or from the RTS, DTS lines on each RS232 port.

    Here is a basic one way RS232 program, this can be expanded quite easily with a bit more code to check responses etc. This is a demonstration only:

    This program send strings out of serial port 1 when C-Bus trigger GA 1 is set to the desired level.


    [Initialisation]
    OpenSerial(1, 1, 9600, 8, 1, 0, 0);

    [Module]
    if GetTriggerLevel("Group 1") > 0 then
    begin
    SerialAction;
    end;

    [Procedure]
    procedure SerialAction;

    var
    Action:Integer;
    RS232code:String;

    begin
    Action := GetLightingLevel("Group 1");
    case Action of
    1 : RS232code:='PowerOn';
    2 : RS232code:='PowerOff';
    3 : RS232code:='Mute';
    4 : RS232code:='ChannelUp';
    end;
    WriteSerial(1, RS232code);
    SetCBusState("Local", "Trigger Control", "Group 1", OFF);
    end;


    Regards,
    Matty
     
    Matty, Jan 23, 2006
    #11
  12. richy

    richy

    Joined:
    Aug 8, 2004
    Messages:
    88
    Likes Received:
    0
    Location:
    VIC
    Hi guys thanks for the response.

    Yes, I have connected the 24AC adapter, I figured it would not work to good without.

    Ok, so I must dissconect the USB cable before, expecting the PAC to work standalone.

    Ok, OpenSerial(1, 1, 19200, 8, 1, 0, 0) so the ComPortNo. is irrelevant to the PAC.

    Considering the Sample code you supplied Alex, its clear that I need to write my own code to read commands I'm sending to the port. This is great in a way, since I dont need to send all the code needed, as per the PC-Int. Should reduce some latency, I was experiencing.

    Also, Matty,
    with your snippet, will that module poll C-bus continually. is there a way to enable this module to run when a group has been set to ON.
    I know I can do this inside HomeGate, but thats via the GUi programming, I can actually select the button to enable a specific module.

    How would I enable a module, when a desired group address comes on.

    Cheers guys,

    Thanks for the feed back ...
     
    richy, Jan 24, 2006
    #12
  13. richy

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    Write/ReadSerial

    Richy

    Have a look at the attached file in this thread.
    http://www.cbusforums.com/forums/showthread.php?t=1845

    You can copy the example given pretty much one for one (obviously using your desired 232 packets)

    Important:

    You have to open the serial port at the appropriate speed and settings. You need the external power supply 16-24v AC. In a module read the serial port into a string each loop. If the serial port is opened in the initialise section and there is serial comms coming into the unit without being read out the serial buffer in the C-Bus unit will fill up and does not truncate.

    The example program in the previous link has many comments which should make things clear for an easy way to read and write serial.

    Let me know if it helps.
     
    Phil.H, Jan 24, 2006
    #13
  14. richy

    richy

    Joined:
    Aug 8, 2004
    Messages:
    88
    Likes Received:
    0
    Location:
    VIC
    Thanks Phil

    It's already making more sense.

    I have written ASCII to the port, and hey it worked.
    But only ever works the first time.

    So I may have an issue with the buffer filling up.

    I'll read the link and get back to you ...

    I'll be up all night on this one, I want to get it working tonight ...
    and working reliable ...
     
    richy, Jan 24, 2006
    #14
  15. richy

    richy

    Joined:
    Aug 8, 2004
    Messages:
    88
    Likes Received:
    0
    Location:
    VIC
    Phil.H

    Your the man ...

    Here I am writing all this complex code. becuase I'm thinking that the simple way to do it, is just too simple, and couldn't possibly work.
    I'm writing modules for every command. Initializing strings. etc.. etc...

    Then I look at your code, and think, no cant be so simple.

    Give it a go, and it works every time.

    Like I said, your the man ...

    I like the way you setup the Write and Read, were you used a LightingState to trigger the write ...

    And its lovely that one of the devices, I am controlling is a Axium.

    Now the tediuos task of setting up all the constants for my devices.

    Axium 2750i
    DenonAVR 3805
    Hitachi PJTX100

    Anyone want the code, put your hand up ....

    Cheers.


    PS: Phil, instead of all those If Statements, do you think a "case" would be better ... ? also how much latency would you expect after you have about 50 or so If statements?
     
    richy, Jan 24, 2006
    #15
  16. richy

    Matty

    Joined:
    Oct 15, 2004
    Messages:
    131
    Likes Received:
    0
    Richy,

    The snippet of code doesn't actually poll the bus, but it does continually check the state of the GA. To enable a module according to a GA would be the same in PAC as in homegate, here's and example:

    once GetLightingState("Group 1") then
    EnableModule("Next module");

    once GetLightingState("Group 1")=OFF then
    DisableModule("Next module");


    The number you assign here is the number that you use to when addressing the port that you are reading from and writing to. In the OpenSerial string the first number is the 'serial port index', you could assign this as say 9. The second number is the com port, on the PAC this is 1 or 2. Lets use com port number 1 in the following example:
    OpenSerial(9, 1, 9600, 8, 1, 0, 0);
    Then to read:
    ReadSerial(9, InString, #13#10);
    Then to write:
    WriteSerial(9, SendString);

    Regards,
    Matty
     
    Matty, Jan 24, 2006
    #16
  17. richy

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    Simple Serial

    First, I am glad the example code has helped you, that is why I wrote it for. Now you have the basics right you are obviously moving on.

    Several (many) 'if' statements are not necessarily a problem. Be careful, if is evaluated on every loop and we don't always want to generate an action on every loop if the condition stays true, especially a C-Bus command, that is what 'once' is there for.

    If you have the opportunity to use "case" this is usually more efficient than many if statements, just be careful to ensure you do not end up with a value of your "SelectorExpression" that is not in you CaseList or you will get a runtime error... Hope this makes sense.

    The serial read utility Darren wrote for me will be a big help for people like you. I will get it on the forum here later today. (Back at work and time is skinny)

    The example code I wrote is not necessarily the most efficient way of doing things. I wrote it to make it very understandable to kick people off in the right direction. Then those who have the capibility like you can move on from there without soaking up too much time. Looks like I might have helped one person at least :D

    If you end up with sample code for the other devices you mention then drop it in the forum. The other thing that is very very handy is any document from the equipment manufacturer covering the equipment serial arrangements.
     
    Phil.H, Jan 24, 2006
    #17
  18. richy

    richy

    Joined:
    Aug 8, 2004
    Messages:
    88
    Likes Received:
    0
    Location:
    VIC
    Phil

    You have actually helped me more than you think. Lastnight and Today has been very productive. I have managed to :-

    Read Serial into the PAC, from a third party Device (happens to be a RTI T3).
    Act on this serial input and
    Write Serial from the PAC to control my Axium 2750i.
    I have also been able to utilize the extra com ports in my HomeGate Machine to:-
    Read Serial in, again from my T3, act on this serial input and
    Write Serial via the PAC, and also via the spare com ports on my HomeGate PC to control my DenonAVR3805 + Axium 2750i.

    It works very nicely and the lag time is actually quite good to my surprise, hardly noticable.

    Also thanks to Matty, as his valuable input will help me turn a B&W Touch Screen into a Multiroom audio controller.

    All is going well, except for my stupid Projector. Has a unusual Protocol for RS232 and everything is specified in hex. Cant seem to get it working yet.


    Other than that, I'll dump the code for my RS232 control when I'm done.

    PS: do we have a repository online, were people can upload code, I thought I read something about this, can't find it again .... ??

    Also have some other logic code that controls all my blinds, if anyone is interested. Yet to be commented though.

    PS: Phil, its good to see you write more comments than code ...:) something I need to master ...
     
    richy, Jan 25, 2006
    #18
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.