SerialEx - an "improved" Serial2 library

Discussion in 'Additional Libraries' started by agraham, Nov 19, 2008.

  1. agraham

    agraham Expert Licensed 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.
     

    Attached Files:

    Last edited: Nov 19, 2008
  2. DaveW

    DaveW Active Member Licensed 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.basic4ppc.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.
     
  3. agraham

    agraham Expert Licensed User

    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.

    Possible yes, probable no - unless I have another reason to release an updated version of the library.
     
  4. DaveW

    DaveW Active Member Licensed User

    That's fine :) I just wondered ;)

    David.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that it is a good idea. Currently both libraries will be merged during compilation.
     
  6. agraham

    agraham Expert Licensed User

    IF I ever did do it I would write the device COM port Registry search into the SerialEx.GetPorts method. I didn't mean that I would merge the two libraries into one!
     
  7. Cableguy

    Cableguy Expert Licensed 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?
     
  8. agraham

    agraham Expert Licensed User

    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.
     
  9. Cableguy

    Cableguy Expert Licensed User

    So If I really need to set the value to zero, is there any workaround?
     
  10. agraham

    agraham Expert Licensed User

    No, but I'd be very surprised (astonished even) if any modern equipment required the use of 0 stop bits.
     
  11. mjcoon

    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.
     
  12. agraham

    agraham Expert Licensed User

    Yes it is. The perils of cut and paste multiplying an original typo :(

    Aren't the defaults detailed in the descriptions of New1 and New2 sufficient?
     
  13. mjcoon

    mjcoon Well-Known Member Licensed User

    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.
     
  14. agraham

    agraham Expert Licensed User

    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.
     
  15. Sinager

    Sinager New Member Licensed User

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

    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.
     
  17. agraham

    agraham Expert Licensed User

    I've no idea. What GetPorts gives you is the array of serial port names that the .NET SerialPort class returns.
     
  18. formazione

    formazione Member Licensed 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
     
  19. agraham

    agraham Expert Licensed User

    No, unless there is some flow control kicking in at the device.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice