Page 1 of 1
Send Data to com port
Posted: Mon Oct 30, 2006 6:08 pm
by Pedromlo
Hi everyone,
I need to send some commands to the serial ports.
The thing is that the commands need to be constructed on VB code depending on variables configured on HB. So, i think the command association of the device with the hardware does not fit me.
Can anyone give me a clue or a piece of code on how to write data directly to one com port?
Thank you all
regards
Pedro
Posted: Tue Oct 31, 2006 4:38 am
by yaccri
One way to do it is to:
- Use VBScript with GetPropertyValue for formatting
- Use VBScript with SetPropertyValue to set the property of a generic serial device with the fomatted message.
Posted: Tue Oct 31, 2006 6:32 am
by Pedromlo
Hi yaccri,
Thats the way to store the message, but what i need to know is how to send it. Is there some function like 'SendData' or so?
Posted: Tue Oct 31, 2006 10:44 am
by ScottBot
There are very few 'functions' in HouseBot. The functions in the scripting language are really just APIs to do very general things (like getting and setting property values) that you can do in the UI. For the most part, HouseBot doesn't bother the user with 'how' to do something (action/function), it just expects the user to tell 'what' the final state is. So as soon as you set a Property Value anywhere in the system (including a VB Script), the appropriate measures are taken to make that state change happen.
Check out
this post. The user had a similar question.
Posted: Tue Oct 31, 2006 11:54 am
by Pedromlo
Thanks Scott,
I will try the instructions on the other post, and i will get there.
Posted: Tue Oct 31, 2006 12:37 pm
by Pedromlo
Hi Scott,
If i construct a HEX string for example like '050002' and save it in a property value linked to a command on hardware like '%1%'.
Do you think this will work?
Or the string would be '502' and then the command would be '%x%'?
Or the string would be '502' and then the command would be '%1%' with DATA TYPE configured as HEX on command configuration?
Best Regards
Posted: Tue Oct 31, 2006 9:57 pm
by ScottBot
It really depends on the equipment you are interfacing to. If you use %x%, it will take the data and parse it out as two character hex. It will send the numeric value and not the ASCII value.
So if you sent A0 using the %x% escape sequence, it would send 10100000
But if you sent it with %1%, it would send ASCII A(=0x41) and 0(=0x00) 0100000100000000
I think this is right... but it's been a while since I've been through the configuration on this, so I could be mistaken. I'd suggest consulting the equipment RS232 spec and just trying the different options.