SerialEx - an "improved" Serial2 library

agraham

Expert
Licensed User
Longtime User
I produced this library to overcome a few shortcomings with the Serial2 library, in particular using it for binary data transfers. You can read what they are in the help. This library is a superset of Serial2 with additional events for errors and pin changes and is an almost complete exposure of the .NET SerialPort class.

Help and source for merging together with the libary are in the attachment. I didn't bother with a demo for this library - use one for Serial2 and expand it if you want to experiment.
 

Attachments

  • SerialEx1.1.zip
    28.2 KB · Views: 514
Last edited:

DaveW

Active Member
Licensed User
Longtime User
Hi Andrew,

I have just transferred my app from the PC to the device and discovered that the GetPorts method does not return the full list of available ports on a device. I only got COM1, 2, 4, & 3. I had to use the Registry to do it (http://www.b4x.com/forum/code-samples-tips/314-reading-com-ports-information-registry.html). This returned 1 to 8 (including the bluetooth ports)

Is there any particular reason for this? Would it be possible to merge the Registry functionality into the SerialEx dll?

David.
 

agraham

Expert
Licensed User
Longtime User
Is there any particular reason for this?
The .NET SerialPort GetPorts method gets its information from the Registry using the entries under HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM which is valid on both device and desktop. Erel's code uses HKEY_LOCAL_MACHINE\DRIVERS\ACTIVE which only exists on the device. I don't know what the difference is.

Would it be possible to merge the Registry functionality into the SerialEx dll?
Possible yes, probable no - unless I have another reason to release an updated version of the library.
 

Cableguy

Expert
Licensed User
Longtime User
StopBits=0 gives me an error stating "Enumvalue was out of Legal Range."
StopBits=1 works with no erros...

But I'm still in the configuring the com port, so I haven't even opened it yet...
Can this be a bug?
 

agraham

Expert
Licensed User
Longtime User
Can this be a bug?
No, it seems deliberate on Microsofts part for some reason. The StopBits enumeration is documented to have (and actually has when checked with Reflector) the four values shown in the help, 0, 1, 1.5 or 2 and most hardware can support these. However when I look with Reflector inside the SerialPort class, for some reason known only to whoever wrote that software, it is deliberately programmed to only accept either 1 or 1.5 stop bits. I have no idea why this limitation exists! 1 stop bit is universal nowadays, I haven't seen 1.5 used since the days of 5 hole mechanical teletype machines.
 

Cableguy

Expert
Licensed User
Longtime User
So If I really need to set the value to zero, is there any workaround?
 

mjcoon

Well-Known Member
Licensed User
Hi Andrew, I am returning to battle with the problems I was having with binary serial data acquisition last year (now having retired...).

So am delighted to find this library that may enable me to overcome my problem that could have been Ctrl-Z related.

BTW the "Help" with this library mentions Ctl-Z four times and each time gives its value as 0x0a whereas I'm sure it is 0x1a as given in the separate discussion.

Also, a plea: could the "Help" give the default values of the properties, espcially the new SerialEx ones? The we can avoid cluttering code with default settings that are spurious.
 

agraham

Expert
Licensed User
Longtime User
BTW the "Help" with this library mentions Ctl-Z four times and each time gives its value as 0x0a whereas I'm sure it is 0x1a as given in the separate discussion.
Yes it is. The perils of cut and paste multiplying an original typo :(

could the "Help" give the default values of the properties, espcially the new SerialEx ones?
Aren't the defaults detailed in the descriptions of New1 and New2 sufficient?
 

mjcoon

Well-Known Member
Licensed User
Aren't the defaults detailed in the descriptions of New1 and New2 sufficient?

Hi again Andrew; I think the answer must be "almost"! Really, I think I should be able to guess the default values of: EnableOnComm (True); EnableOnEof (True because this was the old behaviour); EnableOnPinChanged (False because it is new behavour); EnableOnPinChanged (False because it is new behavour).

Best regards, Mike.
 

agraham

Expert
Licensed User
Longtime User
I think I should be able to guess the default values
I assume you meant EnableOnError instead of one of the EnablePinChangeds. You could always read them back instead of guessing - but in fact they are all False :).

Your reasoning is sound except that as Serial2.dll defaults to EnableOnComm = False I made SerialEx the same. I didn't set EnableOnEof = True as I didn't want to automatically enable the deviant behaviour which was the reason for this new library. I wanted to be able drop SerialEx into a problematic Serial2 app without changing any code and for it to just work.
 

Sinager

New Member
Licensed User
I produced this library to overcome a few shortcomings with the Serial2 library

thank you, this saved my project as Serial2 was translating into "?"s a number of different characters making incoming strings unusable
 

Zenerdiode

Active Member
Licensed User
SerialEx.GetPorts on the Desktop reports some of my ports with the suffix "i". Why is this?

Ports 4,5,6, & 7 in this case.
 

formazione

Member
Licensed User
Longtime User
Hi,
I have a problem, I'm developing a program that send serial commands and receive info from device instead of use "free serial port terminal" program as I usually do.
I can open the port, read string data from device but I can't send commands to the device. Have you any idea why it doesn't work?

Thanks in advance
 
Top