Jump to content


Photo

Rs232 #2


  • Please log in to reply
55 replies to this topic

#1 andbna

andbna

    GMC Member

  • GMC Member
  • 323 posts

Posted 29 October 2007 - 10:26 PM

I'm back and using GM again... it's been a while. Since I’ve gotten a number of Emails asking about the RS232 DLL, I figured I would rewrite it and support it again.

So, this new version of the DLL has a bunch of different functions (I lost the old source code so I just rewrote it from scratch)
Most importantly is the addition of a SetTimeouts function which allows you to specify how long a read/write function should wait before returning (this way, the read functions won't hang if there’s no input.)

It's available as both a DLL with scripts and a GM7 extension. Small examples for each are included.
Download it here: RS232DLL.zip

EDIT: Added a flow control function.

Enjoy
-Andrew

Edited by andbna, 19 January 2008 - 03:45 AM.

  • 1

#2 Mister_M

Mister_M

    GMC Member

  • New Member
  • 499 posts

Posted 29 October 2007 - 11:21 PM

Wow a timeout system! Just what i needed!
Thanks!
  • 0

#3 andbna

andbna

    GMC Member

  • GMC Member
  • 323 posts

Posted 30 October 2007 - 04:30 AM

Your most welcome :lol:

and, It appears I made a few typos in the GM6 script. It's been fixed now :D

Cheers
-Andrew
  • 0

#4 Robot Freak

Robot Freak

    GMC Member

  • New Member
  • 271 posts

Posted 30 October 2007 - 01:53 PM

The previous version wasn't able to communicate with my RS232 microcontroller. Lets see if this one works!
  • 0

#5 contactnero

contactnero

    GMC Member

  • GMC Member
  • 12 posts

Posted 07 January 2008 - 07:01 PM

The previous version wasn't able to communicate with my RS232 microcontroller. Lets see if this one works!

<{POST_SNAPBACK}>


So, is this version able to communicate with your RS232 microcontroller?
  • 0

#6 FlipSide

FlipSide

    GMC Member

  • New Member
  • 281 posts

Posted 14 January 2008 - 01:03 AM

.

Edited by FlipSide, 16 October 2009 - 01:32 AM.

  • 0

#7 andbna

andbna

    GMC Member

  • GMC Member
  • 323 posts

Posted 14 January 2008 - 11:08 PM

The order is detailed in the Help.txt It's pretty clear. And yes you need to call it after RS232_CreatePort so you can pass it a port ID.

If anyone needs to modify, or get any additional properties, let me know and il make the appropriate functions.

-Andrew

Edited by andbna, 14 January 2008 - 11:09 PM.

  • 0

#8 FlipSide

FlipSide

    GMC Member

  • New Member
  • 281 posts

Posted 15 January 2008 - 09:10 PM

.

Edited by FlipSide, 16 October 2009 - 01:32 AM.

  • 0

#9 Robot Freak

Robot Freak

    GMC Member

  • New Member
  • 271 posts

Posted 16 January 2008 - 09:00 PM

The previous version wasn't able to communicate with my RS232 microcontroller. Lets see if this one works!

<{POST_SNAPBACK}>


So, is this version able to communicate with your RS232 microcontroller?

<{POST_SNAPBACK}>

No.
  • 0

#10 andbna

andbna

    GMC Member

  • GMC Member
  • 323 posts

Posted 17 January 2008 - 12:46 AM

Robot Freak, would you like me to help you try and get it working?

And il add the flow control by friday.

-Andrew
  • 0

#11 Robot Freak

Robot Freak

    GMC Member

  • New Member
  • 271 posts

Posted 17 January 2008 - 09:26 PM

That would be great, I'm trying to send to/receive from the Javelin Stamp, see www.parallax.com
  • 0

#12 Robot Freak

Robot Freak

    GMC Member

  • New Member
  • 271 posts

Posted 18 January 2008 - 10:24 AM

When I open the GM6 example, I get:
ERROR in
action number 1
of Create Event
for object COM1:

Error defining an external function.
For every external_define in the startup script...
The GM7 example says 'Error creating COM5'.
Maybe the DLL is defined wrong?

Edited by Robot Freak, 18 January 2008 - 10:26 AM.

  • 0

#13 andbna

andbna

    GMC Member

  • GMC Member
  • 323 posts

Posted 19 January 2008 - 03:44 AM

Ok, I have added a SetFlowControl function, and updated the DLL, let me know if it doesn't work Turbe.

RobotFreak:
Make sure you extract the .gm6 and the DLL into the same folder before you open the .gm6.

The GM7 error would mean that it could not find the COM port, post or PM me what arguments you used, and make sure you can find the appropriate port in your device manager.

-Andrew
  • 0

#14 FlipSide

FlipSide

    GMC Member

  • New Member
  • 281 posts

Posted 21 January 2008 - 04:57 PM

.

Edited by FlipSide, 16 October 2009 - 01:34 AM.

  • 0

#15 FlipSide

FlipSide

    GMC Member

  • New Member
  • 281 posts

Posted 21 January 2008 - 05:45 PM

.

Edited by FlipSide, 16 October 2009 - 01:34 AM.

  • 0

#16 andbna

andbna

    GMC Member

  • GMC Member
  • 323 posts

Posted 21 January 2008 - 10:24 PM

To remove all flow controll, while most arguments are 0/false, fTXContinueOnXoff should be true;

RS232_SetFlowControl(0,0,0,1,0,0,0,0,0,0,0,0,1)

Specifies No Flow Control.

For software flow control using Xon/Xoff characters,
You need to set XonLim and XoffLim values.

XonLim and XoffLim are used to prevent the input buffer from overflowing. I believe the help file is wrong here, I will ammend it... looking at the MSDN page, it contradicts itself, those were taken directly from one of it's pages, here are correct descriptions from another of its pages:

"XonLim
Specifies the maximum number of bytes allowed in the queue.

The XON character is sent if the number of bytes in the queue falls below this number."

"XoffLim
Specifies the maximum number of bytes accepted in the input buffer before the XOFF character is sent.

The maximum number of bytes accepted is calculated by subtracting this value from the size, in bytes, of the input buffer." This one should be non-zero.

XoffLim specifies how full you want to let the input buffer get before requesting that the periphrial stop transmitting. So if our input buffer can handle 500bytes maximum, and I want to leave 100bytes in it just in case it needs to send a few extra bytes of data when I ask it to stop, I set XoffLim to 100. Setting it to 0 would resault in a buffer overflow if it got filled and the device decided to send an extra byte allong.
How much room you want to leave really depends on the application and device.

XonLim is similar, except you specify how empty you want the buffer to get before you start transmitting again.

Example:

Assuming the input buffer is 500bytes, Xofflim is 100, and XonLim is 10:

Device transmits untill the input buffer has 400bytes (500-(XoffLim=100) =400) when it's told to stop, but maby it needs to send 5 extra bytes to finish up the data its transmiting.
Input buffer contains 405bytes, now your application begins reading data from the buffer, and brings it down to 20bytes still left in the buffer, then has to process the data. The XonLim has not been reached so the device still is holding back transmiting data. The application collects more information from the buffer and brings it down to 9bytes before deciding to process the data. Since XonLim is 10, and 9 is less than 10, the device is told it can start transmitting again.
Repeat ad nauseum.

With that example, the flow control function call would look like this:
RS232_SetFlowControl(0,0,0,0,1,1,0,0,10,100,17,19,
1)

To use the RTS/CTS flow control only (which is 1-way; it assumes the computer is always ready to recieve input)

Set fOutxCtsFlow to true, and fRtsControl to non-zero (1 will mean the line is always high, 3 means it's high while there is data to be sent, and 2 is a handshaking methode. 3 is probably preffered.)
I'm Not sure if the XonLim and XoffLim actualy need values for this; I can't see why they would be relevent, but you can test.
The RTS line will let your device know when theres data ready to be sent, and the CTS line will tell the computer whether it should send or not.

RS232_SetFlowControl(1,0,0,1,0,0,0,3,0,0,0,0,1) //Assuming the XonLim and XoffLim is irrelevent

Finaly, I'l look into a function to check which ports are available.
-Andrew
  • 2

#17 FlipSide

FlipSide

    GMC Member

  • New Member
  • 281 posts

Posted 22 January 2008 - 02:17 AM

.

Edited by FlipSide, 16 October 2009 - 01:34 AM.

  • 0

#18 FlipSide

FlipSide

    GMC Member

  • New Member
  • 281 posts

Posted 04 February 2008 - 04:47 PM

.

Edited by FlipSide, 16 October 2009 - 01:35 AM.

  • 0

#19 andbna

andbna

    GMC Member

  • GMC Member
  • 323 posts

Posted 04 February 2008 - 08:56 PM

The extension's included in the ZIP, in the GM7 folder.

And the available ports will have to wait, it doesn't look like Windows has standard API for it, and I have an ancient civilization to create :)

-Andrew
  • 0

#20 FlipSide

FlipSide

    GMC Member

  • New Member
  • 281 posts

Posted 05 February 2008 - 02:24 AM

.

Edited by FlipSide, 16 October 2009 - 01:35 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users