Jump to content

Serial Port /COM Port UDF


martin
 Share

Recommended Posts

Hi Martin,

First of all thanks for UDF!

And now a question:

I try to create "not standard" protocol, namely 9 bit of data. As soon as I set $iBits = 9, I receive an error -4. I have tried to set value less than 8 (7) and the error is not present. It is a bug or I do something wrong?

Error -4 means that you chose a number of data bits which I don't support. Actually I have only allowed for 7 or 8. I can easily add 5 and 6 but I don't know about 9. I'll post back here when I find out.

EDIT: See post #144

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.
Link to comment
Share on other sites

Its been ages since i played with this..

http://www.autoitscript.com/forum/index.ph...c=42452&hl=

But wouldnt mind doing it again ^^

Nice work!

@RAMzor

As far as I can tell 9 data bits is not possible on a Windows PC due to hardware limitation. (UART design).

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.
Link to comment
Share on other sites

  • 1 month later...

Hi Martin,

Have you noticed any problems with no-us versions of vista? I have a few users using other language version of vista (Italian and German). One user is using x64 and the other is using x32. Neither can get their gps to work with my program when using CommMG. If the x32 user uses netcomm instead his gps works fine.(x64 user does not have that option)

The error my program is giving indicates that it is failing on the _CommSetPort function.

Any know compatibility issues? something EU version of vista are missing maybe?

btw, the program i am talking about is my vistumbler wireless scanner (Vistumbler.net)

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Hi Martin,

Have you noticed any problems with no-us versions of vista? I have a few users using other language version of vista (Italian and German). One user is using x64 and the other is using x32. Neither can get their gps to work with my program when using CommMG. If the x32 user uses netcomm instead his gps works fine.(x64 user does not have that option)

The error my program is giving indicates that it is failing on the _CommSetPort function.

Any know compatibility issues? something EU version of vista are missing maybe?

btw, the program i am talking about is my vistumbler wireless scanner (Vistumbler.net)

Hi ACalcutt,

I don't have much experiance of Vista but enough to know you can have unexpected problems. I have an AutoIt script which uses the Scilexer.dll and although Scite uses it and there is no problem, my script crashes on Vista 32 bit but not on Vista 64 and not on XP.

Anyway, I didn't know there was a problem with the CommMG udf or the dll. I'l find out but it will be the middle of next week before I can tell you what I've found. Do you know if they can list the ports ok?

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.
Link to comment
Share on other sites

Hi ACalcutt,

I don't have much experiance of Vista but enough to know you can have unexpected problems. I have an AutoIt script which uses the Scilexer.dll and although Scite uses it and there is no problem, my script crashes on Vista 32 bit but not on Vista 64 and not on XP.

Anyway, I didn't know there was a problem with the CommMG udf or the dll. I'l find out but it will be the middle of next week before I can tell you what I've found. Do you know if they can list the ports ok?

I don't know... I'll see if i can find out

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Thanks for the udf, works great.

I have a problem here with my servo controller and servo from parallax... well actually i have no idea how to change position on the servo.

i connect and ping it fine but i have no idea what to send it to change position.

I tried this

$Starting = "!SC"
$Cpara = "15"           ;servo is on spot 15
$Rpara = "7"             ;movement set to 7
$Lowbyte = "1011"
$Highbyte = "1011"

_CommSendString($Starting & $Cpara & $Rpara & $Lowbyte & $Highbyte & @CR, 1)
Sleep(500)
FileWriteLine($file, "" &_NowTime() &"Servo position moved to " & $Lowbyte)oÝ÷ Ù8^·W(!¶Ì!zx¬zwbµ»­×hzÉíÞêÞË(è§~ë¢kazf§¹©ZºÚ"µÍÞ[^$ÉÌÌÎÔÐåÈËÕÐUKËQÒUK  ÌÍÌNÛBÈÛÛÛHÙË[ÝH]ÝÜ]HHÜÚ][ÛÛÛ[X[ÈHÐËXXÚÜÚ][ÛÛÛ[X[ÈÛÛÙYÙHXYYH[Y]ÎË[Ë[HÛÛ[X[Z[]ÜHXY$ÉÌÌÎÔÐåÈHXYHXYÚYÛYYÈÈ[]XÙÈÛHØ[YHÚH]ÈÈBÛÛ[X[ÜHÙÈÛÛÛHÈ[Y]ÈH[H[XLÌHÛÜÜÛ[ÈÈHÙÈÚ[[[XHÙÂÚ[[[XÚÝ[HLMBH[Y]ÈH[H[X%
È]ÛÛÛÈH[[Ý[ÛÜXXÚÚ[[YH[[Y]ÈÙ]È[[ÈÈØXY[H[ÙHÚYÚ[HÙ]ÈH[Y]Ù[[[YYX][K[[YÈÙKMÈÛÜÜÛÈÜYYÈÛH/ÙHÙXÛÛÈ
ÙXÛÛÈÜH[L  ÎMMÜÈÈLÈ^ÝÚ[ÛÜÝ[ÙÜËÈÛÜ[][ÛÈ][XÝYÚÈ]X][ÛÙ[H^ÝËH[Y]ÈHMX]ÛÜ]ÛÜÜÛÈÈHÚYÙÈÜÚ][ÛH[ÙK
LLLL
KÛÜÜÛÈÈÈNYÜYÈÙÙÈÝ][ÛÚ]XXÚÝ]X[[È   ÎMMÜËHÛÛ[X[Z[]Ü   ÌÍÌ
ÔK]ÝÝHÛZ]Y

Sorry if this is the wrong place to ask.

Link to comment
Share on other sites

Heyyy...

I update my Autoit to the last version and when i run the the CommgExample I need to put more libraries to it work.

Now I´m getting a problem with a script that is working in a computer that is next to me but in mine it doesn´t work...

The problem is with this part of the code

$portnumb = _CommListPorts(0)
    If @error = 1 Then 
        MsgBox(0,'trouble getting portlist','Program will terminate!')
        Exit
    EndIf
        
    For $pl = 1 To $portnumb[0]
        GUICtrlSetData($Port,$portnumb[$pl])
    Next
    GUICtrlSetData($Port,$portnumb[1])
    
    WinActivate($janelac)

I'm getting this error:

==> Subscript used with non-Array variable.:

For $pl = 1 To $portnumb[0]

For $pl = 1 To $portnumb^ ERROR

Some tip??? :)

Brunomusw

Link to comment
Share on other sites

Heyyy...

I update my Autoit to the last version and when i run the the CommgExample I need to put more libraries to it work.

Now I´m getting a problem with a script that is working in a computer that is next to me but in mine it doesn´t work...

The problem is with this part of the code

$portnumb = _CommListPorts(0)
    If @error = 1 Then 
        MsgBox(0,'trouble getting portlist','Program will terminate!')
        Exit
    EndIf
        
    For $pl = 1 To $portnumb[0]
        GUICtrlSetData($Port,$portnumb[$pl])
    Next
    GUICtrlSetData($Port,$portnumb[1])
    
    WinActivate($janelac)

I'm getting this error:

==> Subscript used with non-Array variable.:

For $pl = 1 To $portnumb[0]

For $pl = 1 To $portnumb^ ERROR

Some tip??? :)

Brunomusw

If I run the udf with the lates versions I don't need to add any libraries, so can you tell me what the versions are you are using for the UDF and the DLL?

The problem is, or should be, that no serial ports are detected. What do you see on the PC with a problem if you look Control Panel|System| Device Manager|Ports(COM & LPT)? I would expect that there are no COM ports.

The code should have checked to see if any ports were found. (It is possibly copied from an example of mine where I made this mistake.)

$portnumb = _CommListPorts(0)
    If @error = 1 Then 
        MsgBox(0,'trouble getting portlist','Program will terminate!')
        Exit
    EndIf
        
    If IsArray($portnumb) then
           For $pl = 1 To $portnumb[0]
        GUICtrlSetData($Port,$portnumb[$pl])
      Next
      GUICtrlSetData($Port,$portnumb[1])
    Else
       MsgBox(262144,"ERROR",No COM ports found on this PC.")
    EndIf
    
    WinActivate($janelac)

If you have a Serial port to USB adapter you could install that on the problem PC and see if it made a difference.

Otherwise I don't know the answer, so I would be interested to know the OS. ACalcutt has reported problems on Vista, but so far I haven't found why that might be, howvevr in ACalcutt's case the problem wasn't with detecting the ports.

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.
Link to comment
Share on other sites

$portnumb = _CommListPorts(0)

I'm getting this error:

==> Subscript used with non-Array variable.:

For $pl = 1 To $portnumb[0]

For $pl = 1 To $portnumb^ ERROR

Note also that _CommListPorts() takes a second, optional, parameter which changes the return type. By default the current code base returns an array but it can be changed to a single string by passing 0 as the second parameter. Perhaps the default behavior of the current releases may have changed from early versions.

-brendan

Link to comment
Share on other sites

Note also that _CommListPorts() takes a second, optional, parameter which changes the return type. By default the current code base returns an array but it can be changed to a single string by passing 0 as the second parameter. Perhaps the default behavior of the current releases may have changed from early versions.

-brendan

I don't think that function changed and I can't find any version which has an optional second parameter.

;===============================================================================
;
; Function Name:  _CommListPorts($iReturnType=1)
; Description:  Gets the list of available ports seperated by '|' or as an array
;
; Parameters:    $iReturnType -  integer:if $iReturnType = 1 then return a string with the list of COM ports seperated by '|'
;                                        if $iReturnType <> 1 then return an array of strings, with element [0] holding the number of COM ports
; Returns;  on success - a string eg 'COM1|COM8', or array eg ['2','COM1','COM2']
;          on failure - an empty string and @error set to 1 if dll could not list any ports
;                                           @error set to 2 id dll not open and couldn't be opened

;===============================================================================

Which points out something that brunomusw should check, what is @error after calling the function?

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.
Link to comment
Share on other sites

With the sample code i can not receive any data from the serial port (PALM OS device) however i can send data to PALM (with VB6 i dont have problems but i prefer the AUTOIT)

Is correct the function to receive data or i am wrong in something"

sorry for my english

Thanks in advance

ABB

Link to comment
Share on other sites

With the sample code i can not receive any data from the serial port (PALM OS device) however i can send data to PALM (with VB6 i dont have problems but i prefer the AUTOIT)

Is correct the function to receive data or i am wrong in something"

sorry for my english

Thanks in advance

ABB

You should be able to receive data and I would expect that if it can be done in VB then it can be done in AutoIt. Maybe there is some hardware handshaking to set, or some protool to use. Make sure that the port settings are correct such as the baud rate, parity, stop bits and the handshaking method. I regret that I don't know anything about PALM devices.
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.
Link to comment
Share on other sites

You should be able to receive data and I would expect that if it can be done in VB then it can be done in AutoIt. Maybe there is some hardware handshaking to set, or some protool to use. Make sure that the port settings are correct such as the baud rate, parity, stop bits and the handshaking method. I regret that I don't know anything about PALM devices.

The configuration ports thats fine Martin but i can't receive any data but i can write data in the port and receive it in the other device. This example receive only binary data or we can send strings data? maybe the question is wrong but i am newbie

Regards

ABB

Link to comment
Share on other sites

The configuration ports thats fine Martin but i can't receive any data but i can write data in the port and receive it in the other device. This example receive only binary data or we can send strings data? maybe the question is wrong but i am newbie

Regards

ABB

The example doesn't, it recieves strings or characters which it can display.

Can you show some code that you have the problem with and describe what should be received from the PALM device?

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.
Link to comment
Share on other sites

  • 3 weeks later...

I had the exact same error and it was easily resolved by adding the commg.dll file to c:\Windows\System32. It can be downloaded with the UDF on page 1 of this posting

Rgds

eo

Edit - I also ran the program on a machine that didn't have Com ports and got the same error, so Martin has pretty much given you another area to check

I used the example Martin gave as follows in my code and on a Windows Vista machine that does not have Com ports, I now get a message box saying so

Func GetPorts();Find all com ports
  $portlist = _CommListPorts(0);find the available COM ports and write them into the ports combo
  If @error = 1 Then
  MsgBox(0, 'trouble getting portlist', 'Program will terminate!')
  Exit
  EndIf
  If IsArray($portlist) then
  For $pl = 1 To $portlist[0]
  GUICtrlSetData($cmboPortsAvailable1, $portlist[$pl]);_CommListPorts())
  GUICtrlSetData($cmboPortsAvailable2, $portlist[$pl]);_CommListPorts())
  Next
  Else
  MsgBox(262144,"ERROR", "No COM ports found on this PC.")
  EndIf

  EndFunc;==>GetPorts

Heyyy...

I update my Autoit to the last version and when i run the the CommgExample I need to put more libraries to it work.

Now I´m getting a problem with a script that is working in a computer that is next to me but in mine it doesn´t work...

The problem is with this part of the code

$portnumb = _CommListPorts(0)
    If @error = 1 Then 
        MsgBox(0,'trouble getting portlist','Program will terminate!')
        Exit
    EndIf
        
    For $pl = 1 To $portnumb[0]
        GUICtrlSetData($Port,$portnumb[$pl])
    Next
    GUICtrlSetData($Port,$portnumb[1])
    
    WinActivate($janelac)

I'm getting this error:

==> Subscript used with non-Array variable.:

For $pl = 1 To $portnumb[0]

For $pl = 1 To $portnumb^ ERROR

Some tip??? :)

Brunomusw

Edited by eohalloran
Link to comment
Share on other sites

  • 2 months later...

I had the exact same error and it was easily resolved by adding the commg.dll file to c:\Windows\System32. It can be downloaded with the UDF on page 1 of this posting

Rgds

eo

That's it, now it's working without the needed of the commg.dll be on the same paste that the script.

Martin, one question, how could I control a pin on the serial port? I mean like control the pin 7 (request to send), toggle it.

regards,

Brunomusw

Link to comment
Share on other sites

That's it, now it's working without the needed of the commg.dll be on the same paste that the script.

Martin, one question, how could I control a pin on the serial port? I mean like control the pin 7 (request to send), toggle it.

regards,

Brunomusw

I wrote a version which gave greater control over the handshaking lines which might do what you want. It also has some other additions. You would need to set the port twice with different options to toggle the RTS line on and off. The explanation of the settings is given in the comments before the _CommSetport function. I don't remember why this hasn't been included in the current version, maybe there's a problem and you can tell me ^_^

You can get it from here. Because it was experimental I called the dll commgaa.dll and the udf is Commg2_5.au3 instead of commg.au3.

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.
Link to comment
Share on other sites

I wrote a version which gave greater control over the handshaking lines which might do what you want. It also has some other additions. You would need to set the port twice with different options to toggle the RTS line on and off. The explanation of the settings is given in the comments before the _CommSetport function. I don't remember why this hasn't been included in the current version, maybe there's a problem and you can tell me ^_^

You can get it from here. Because it was experimental I called the dll commgaa.dll and the udf is Commg2_5.au3 instead of commg.au3.

Thanks Martin... In some days I'll try it and we came back to talk... ;)

The site that I downloaded the file is a server that you did with autoit? Martin's Autoit Downloader.

Regards,

Brunomusw

Link to comment
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
 Share

×
×
  • Create New...