Sign in to follow this  
Followers 0
RAMzor

How to Serial Port access?

6 posts in this topic

Hi everybody!

How can I sed "*IDN?" string to Serial Port (for TDS2000 Series Digital Ocilloscope)?

I was found Port.dll for port access, and would like to use him in my AutoIt3 script to access a Serial Port.

Can somebody give me a hint/example how to use this dll with DllCall?

Or anyone have anather dll to access a Serial Port?

thanks a lot

Share this post


Link to post
Share on other sites



I tried using the same DLL, but in my case I used it to read COM1...

#include <GUIConstants.au3>
$dll  = DllOpen("port.dll")
$com1 = DllCall($dll,"int","OPENCOM","str","COM1")

$Form1 = GUICreate("COM1", 120, 176, 192, 125)
GUICtrlCreateLabel("COM1 : ", 8, 32, 35, 17)
$Input1 = GUICtrlCreateInput("", 40, 32, 73, 21, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
While 1
  $msg = GuiGetMsg()
  Select
    Case $msg = $GUI_EVENT_CLOSE
      ExitLoop
    Case Else
      $com = DllCall($dll,"int","READBYTE")
      If @error Then $com[0] = "error"
      If $com[0] <> -1 Then GUICtrlSetData($Input1,$com[0])
  EndSelect
WEnd
DllClose($dll)
Exit

For some reason though, it stops receiving input after some time :lmao:

I guess I messed up something... got some code on it from AutoHotKey-forums and tried to convert it, but the DllCall in AutoHotKey seems to work better for this somehow ?!

Anyway, for you the interesting part should be changing "READBYTE" into "SENDBYTE" and using a parameter after this to define what to send.

Hopefully this will work for you... and hopefully somebody will see what's wrong in my code ;)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

There are other references to serial port communication in the forum which you might have seen. I wrote a dll to do the job which is fairly simple; you set the com port (usb to rs232 ports will work) and the baud rate etc. Then you can send a string and receive a string.

The dll is 400K which is very large for what it does, but it works.

Here is a simlified example of how to use it-

$HDll = DllOpen('commg.dll')

;set COM1, 9600 baud, 8 bit,no paraity, 1 stop bit, no flow control
$dllans = DllCall($HDll,'int','SetPort','int','1','int','9600','int','8','int','0','int','1','int','0')

;send a string
$dllans = DllCall($HDll,'int','SendString','str','Something to send' & @CRLF)

;get a string terminated by CR
$str1 = ''
while stringinstr($str1,@CR) = 0
    $ip = DllCall($HDll,'str','GetString','int','1')
    $str1 = $str1 & $ip[0]
WEnd
msgbox(0,'got this back',$str1)

DllClose($HDll)

If anyone wants a copy just ask. (Expect a bit of a delay so I can write some explanations.)

Edit 4th July 2007: Now converted to a serial port UDF which is in the 'example scripts' forum.

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

#4 ·  Posted (edited)

Here are links to a couple of topics dealing with rs232 communications that will provide a solution:

http://www.autoitscript.com/forum/index.php?showtopic=19769

http://www.autoitscript.com/forum/index.php?showtopic=13890

Also, I noticed you're sending SCPI commands to your TDS2000. Have you considered using VISA to communicate with this device? A lot of people don't know that VISA works over the serial port, too. If you decide to do that, AutoIt comes with a series of VISA UDFs that work pretty good. All you need to do is download the VISA runtimes from, say, National Instruments, and you're ready to start DAQ and monitoring with your Osci right away over rs232 with no special com port work.

Incidentally, we have a couple of these Oscis (not the same exact model, but close) and we much prefer to use GPIB (IEEE 488.x) because the acquisition rate is so much higher, and because we can daisy-chain the whole rig. The AutoIt VISA library will work with that, too.

The VISA AutoIt library isn't perfect and doesn't work for all devices, so if you end up needing a more comprehensive library (especially for IEEE 488) let me know and I'll provide you with mine.

-S

Edited by Locodarwin

(Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]

Share this post


Link to post
Share on other sites

Any chance of a copy of that DLL?

Much appreaisted if you could. Other DLL;s not cutting it.

There are other references to serial port communication in the forum which you might have seen. I wrote a dll to do the job which is fairly simple; you set the com port (usb to rs232 ports will work) and the baud rate etc. Then you can send a string and receive a string.

The dll is 400K which is very large for what it does, but it works.

Here is a simlified example of how to use it-

$HDll = DllOpen('commg.dll')

;set COM1, 9600 baud, 8 bit,no paraity, 1 stop bit, no flow control
$dllans = DllCall($HDll,'int','SetPort','int','1','int','9600','int','8','int','0','int','1','int','0')

;send a string
$dllans = DllCall($HDll,'int','SendString','str','Something to send' & @CRLF)

;get a string terminated by CR
$str1 = ''
while stringinstr($str1,@CR) = 0
    $ip = DllCall($HDll,'str','GetString','int','1')
    $str1 = $str1 & $ip[0]
WEnd
msgbox(0,'got this back',$str1)

DllClose($HDll)

If anyone wants a copy just ask. (Expect a bit of a delay so I can write some explanations.)

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