Getting result from serial device

  1. 5 days ago

    Arief S

    Jun 29 Bandung - Indonesia

    Hi,

    I was trying to get the result from a weight calculator, using the example project which is bundled in xojo.
    The one which is using motorolla barcode scanner as an input.

    Its working, but, the result is strange.
    i am expecting the result just a number, but its shows mixed of ascii and number. And its poll every second.

    How to get the result only in one line, not multiple result.
    i want to put the result in a list box.

    Any helps?

    Thanks
    Arief

  2. 4 days ago

    My experience with weird ASCII chars received by serial device is mostly related to wrong Baud rate. But check also all other settings of serial connection: Properties of Serial Connection The serial device manual should tell you how to set the properties of the serial connection.

    "And its poll every second." : Using the event DataReceived of serial connection will trigger every time it receives data from the serial device. I assume the serial device is set the way it sends data every second or when the weight changes.

  3. Mark C

    Jun 29 Testers, Xojo Pro Spain 03170
    Edited 4 days ago

    Hello Arief,

    Sadly your expectation is incorrect, this is a very common expectation, but it is not normally how the serial OS calls can work.

    The serial class is not 'magic' it receives data into its buffers and when the OS decides its time to make the system aware that some data is available then it raises an event, in this case 'DataAvailabe' event.

    you can never expect to receive a complete 'packet' of data each time the 'DataAvailable' event is fired.

    an EVENT is just that, something happened in the OS to make the event occur, that event can be at 1 byte, 10 bytes or all the bytes of data sent from the external device.

    the event has zero intelligence, it can not know what your intentions are for the data.
    you must manage the data when the event occurs.

    this can be done with a timer, POLL the serial port at a defined time, this may allow you to get all the 'packet' data.

    use a 'start' or 'end' character that is searched for in the received stream, this is usually done with 'LookAhead' (my normal way to find 'packet' of data).
    or some other method using 'ReadAll' and then a method to parse the current data for known packet terminators.

    Whatever you do, you will have to parse and manage the data, look for a structure in the received data and determine what is good and bad data, there is nothing in Xojo that can do this for you (and no reason why it should).

    the serial port (in API1, 19r1 and before) is very reliable and I have a significant number of projects and products using the class in Mac, Linux, Raspberry and win, all work without issue, providing you put some work into them.

    if your data is not ASCII values then you need to work on the data in a different way, if it is ASCII it is very easy.

    This may sound a bit complex but it is not.

    so what is your platform and Xojo version number? that is a good start, a copy of the code you have now that does not work will also make it easier to understand what you might be seeing.

    providing you are using API1 serial port I can help you, if you are using API2 (19r2 or 3) then you will need to find someone else to help you as I do not use API2 for any reason.

    Regards

    Mark

  4. 2 days ago

    Arief S

    Jul 1 Bandung - Indonesia

    Hi,

    thanks for the suggestion, I think i am bit close to the solution.

    thanks
    regards,
    arief

  5. Julia T

    Jul 1 Sandy Hook, Connecticut

    Your experience may vary depending on your target platform. Under MacOS, the Xojo serial port tends to "just work". Under Windows I've found things to be very different, and machine-dependent as well, in terms of the DataAvailable event's firing.

or Sign Up to reply!