Sign in to follow this  
Followers 0
trescon

Serial Port with problem ??

2 posts in this topic

Good evening, I planned because I AutoIt sends via serial the contents of a certain variable.

_CommSetport ("1", $ ca, 9600,8,0,1,0,0,0)

_CommSwitch (1)

_CommPortConnection ()

_CommSendString ($ Punti_AD1)

ConsoleWrite ("I sent:" & @ CRLF & $ punti_AD1)

The program works but has a problem encountered when the variable contains a number from 1 to 9 works ok, when the variable contains 0 (zero) the program does not leave anything on the RS-232.

If instead of the command _CommSendString use the command _CommSendByte ("0") the door me out a 0 (zero).

I know how to give assistance to understand where is the mistake?

thanks

Alberto


Thank You

Alberto

---------------------------------------------------

I am translate with Google.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Good evening, I planned because I AutoIt sends via serial the contents of a certain variable.

_CommSetport ("1", $ ca, 9600,8,0,1,0,0,0)

_CommSwitch (1)

_CommPortConnection ()

_CommSendString ($ Punti_AD1)

ConsoleWrite ("I sent:" & @ CRLF & $ punti_AD1)

The program works but has a problem encountered when the variable contains a number from 1 to 9 works ok, when the variable contains 0 (zero) the program does not leave anything on the RS-232.

If instead of the command _CommSendString use the command _CommSendByte ("0") the door me out a 0 (zero).

I know how to give assistance to understand where is the mistake?

thanks

Alberto

If you send a string then you must understand that a string is terminated by a 0 value byte, so if your string includes a byte which is zero you cannot use _CommSendString.

Instead you can use _CommSendByte but the way you have tried to do it is incorrect. The UDF contains an explanation of how each function should be used so you must read it and understand it. The parameter passed to _CommSendByte is an integer. If you want to send the value zero you use

_CommSendByte(0)

If you want to send the letter 'A' then you use

_CommSendByte(Asc('A'))

_CommPortConnection is doing nothing usefule in your example and so it can be removed.

_CommSwitch is correct but if you are only using one COM port then you can ignore it.

The first parameter for _CommSetPort should be an ineteger, eg

_commSetPort(1,....

although I accept that "1" will work.

You can also use _CommSendByteArray but I would advise you to stay with _CommSendByte for the moment.

You could split the string ans send as complete strings the sections that do not contain a zero byte, then use _CommSendByte(0), then send the next string section and so on.

Or you could do something like this

for $i = 0 to StringLen($Punti_AD1) - 1
    _CommSendByte(Asc(StringMid($Punti_AD1,$i,1)))
Next

27May2012 blacklist=trescon

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0