Buffer Serial Data before Transmit
Hello, I am relatively new to LabVIEW and had a question about how to buffer data at the serial port before transmitting. I have attached what I have so far for a VI and this is how I expected it to work.
Read in hexadecimal string (Example: 001122334455)
For loop repeats for half the length of the string because I am transmitting in byte size blocks (Example: 6F)
Reads the first byte of the ascii string and converts it into hexadecimal equivalent byte and transmits.
Repeats until string is completed.
I basically need to place a buffer that fills up until my while loop finishes then transmits all the data at once. Right now there is enough delays between each for loop causes errors.
Any suggestions?
Solved!
Go to Solution.
Attachments:
buffer serial.png 39 KB
Here is a VI that converts the data in the form of <HEX: 00AE 0912 9876 5432> to it's binary equivalent. With a little tuning you should be able to use it to convert your data. This VI is very liberal in how the input data is formatted. The ASCII hex can contain any amount of white space or none at all.
Mark Yedinak
"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Attachments:
Replace Hex Directive.vi 37 KB
Remove All White Space.vi 11 KB
Similar Messages
-
Searching Incoming Serial Data
Greetings!
I was trying to get visual studio to filter through the incoming serial data it is receiving from an Arduino. The program shows the incoming data, so I know the serial port is working, but I'm not sure how to get it to look through that data ( I was thinking
I could use StreamReader to do this). My goal is this: When certain data is received, change the background color of a textbox. I am very new at this and any direction would be appreciated! I feel like i'm throwing spaghetti at a wall...
Here is my current code:
Imports System
Imports System.Threading
Imports System.IO.Ports
Imports System.ComponentModel
Imports System.IO
Public Class Form1
Dim myPort As Array
Delegate Sub SetTextCallBack(ByVal [TEXT] As String)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
myPort = IO.Ports.SerialPort.GetPortNames()
portCmbo.Items.AddRange(myPort)
End Sub
Private Sub startBtn_Click(sender As Object, e As EventArgs) Handles startBtn.Click
SerialPort1.PortName = portCmbo.Text
SerialPort1.BaudRate = baudCmbo.Text
SerialPort1.Open()
startBtn.Enabled = False
closeBtn.Enabled = True
End Sub
Private Sub closeBtn_Click(sender As Object, e As EventArgs) Handles closeBtn.Click
SerialPort1.Close()
startBtn.Enabled = True
closeBtn.Enabled = False
End Sub
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As String)
If Me.inputTxtBox.InvokeRequired Then
Dim x As New SetTextCallBack(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.inputTxtBox.Text &= [text]
End If
End Sub
Private Sub outputTxtBx_TextChanged(sender As Object, e As EventArgs) Handles outputTxtBx.TextChanged
Dim myReader As StreamReader = New StreamReader("Me.inputTxtBox")
Dim line As String = ""
End Sub
End Class
ps: If there is an easier way of doing this, please let me know!You should read a good book on "Communications". When processing received data (from any device) you need to wait until you get the end of message before parsing the data. The data will be received in chunks that can contain from 1
to a million bytes. When you get the word "Hello" you could get "H" then "ello" or "Hel" and then "lo". You can't start looking through the data until you get the entire word "Hello".
So you first have to define a protocol for sending commands to the device and the amount of data that gets returned. So normally you have to terminate a message using one of the following methods
1) Ascii : Terminate a message with a fix character like a return or EOM.
2) Ascii or binary : Includes a bytes count at the beginning of the message.
3) Ascii or binary : Each type message is a fixed length.
You can use combination of the 3 methods above.
jdweng -
Precise time stamping of serial data
I am having trouble with precise timestamping of incoming serial data recived on 4 ports using 4 separate threads that continually attempt to read a byte.
When the expected frame is recieved the data is tagged with a time stamp.
The issue seems to be windows xp or the serial ports themselves. I am using an xsens serial to usb, 2 lavaport serial cards and the built in serial port.
Any suggestions for precise timing?there is some hints:
-for milisecond precise timestamp, you can use GetLocalTime,GetSystemTime or GetTickCount.
But to achieve true milisecond scale, you need use timeBeginPeriod(1)/timeEndPeriod(1) otherwise you get 10-16ms scale depend on system
(please read help pages on msdn for timeBeginPeriod function)
- create your program to not use CPU too much(no pooling,just message and/or sync wait),
or even better, do not run any other apllication which consume lot of CPU/DISK resources on the same PC
- for serial communication (but this also depend on baud rate) you can try to set send/receive driver buffer to 1 (from windows device manager)
- try different serial port card/converter(with different drivers)
- if still need something to try, set higher process and thread priority (SetPriorityClass,SetThreadPriority)
After all of this, on windows, there are no precise timing.Even if you do everything you can do, there is still chance to get time gap, but you can detect it (in milisecond precision) -
I'm not sure how to handle the serial data I'm receiving from a touchscreen panel.
All I want to do is display the two sets of coordinates, which are made up of two 4 digit numbers.
What I'm struggling with, is the carriage return/line feeds (Cr/Lf).
For example I receive,
TP CrLf TP = touchscreen pressed
0100 CrLf 0100 = first set X of coordinates where these values may be anything from 0000 to 4000 and like wise for all coordinates
0200 CrLf 0200 = first set Y of coordinates
TR CrLf TR = touchscreen released
0100 CrLf 0100 = last set of X coordinates
0200 CrLf 0200 = last set of Y coordinates
If the stylus is dragged on the touchscreen, then I may receive numerous TP CrLf plus the coordinates before I final get the touchscreen release set.
If I didn't have all the CrLf's but just one CrLf' after TP nnnn nnnn it wouldn't be problem.
I've had a go using shift registers, but I'm unsure of the best way forward.
Some guidance would be most appreciated.
Solved!
Go to Solution.
Attachments:
Shift1.vi 17 KBI would advise to have several readouts in one iteration of the main loop:
First readout - search the received string for valid command (TP or TR).
If found: run the FOR LOOP to read 2 more times - you will get a string array of your coordinates.
If not found: skip, go to next iteration.
First check this: Each readout should give you one message (TP, TR, or coordinates) and properly terminates on linefeed.
You do not need string concatenations from previous iterations, all shift registers. If not, something is wrong with ViSA settings: wrong termination char, etc. -
How To Managed Serialized Data Over Multiple Application Versions
Lately I've been struggling with deciding how to deal with serialized data between application versions. Assume you have some software that has to be able to save data files. As the application evolves, the data format changes. The application needs to be able to load data saved from prior application versions.
When I first started out I just used a Serializable class. It was quick and easy. However, as newer versions used slightly different data formats, I had to come up with a means to upgrade the data to the latest version. Initially I created a process where the latest data class knows how to upgrade from prior data class versions. Then, when loading data in the application, if the class doesn't match the latest data class version, it checks to see if it matches one of the versions that can be upgraded.
This sort of works, but still has one glaring problem. The old data classes must be etched in stone; never altered. For ever and ever. You can get away with certain simple updates to older data classes by defining a serialVersionUID and keeping it's value the same. But this doesn't always work. What if my overall package structure changes? I have to ensure that the old data classes remain in the same older package structures. Not ideal.
So I've started considering other ways to serialize data...a process where the data can be broken down into core Java classes. There are serializers for serializing to XML, but I don't feel that XML is an appropriate storage format for the data. I'm also considering using a custom built serializer that uses introspection in some fashion.
Before I go any further, however, I'd like to solicit some suggestions. Do you know of any serialization packages that might help me? Do you have any suggestions on what might be a good custom solution? Will Externalizable make this easier? (I've never used Externalizable before...looks like maybe it could help, but even that appears to be vulnerable to refactors that change package structure).
Thanks for your thoughts.I've continued to work on my own custom serialization process as described in my previous post. Here is how it currently works:
In the example there is a class named ExampleSubClass identified by the String "xsub" of version "1.0". It is saved and then reloaded into a class named RevisedExampleSubClass identified by the String "xsub" of version "1.1". The String "xsub" identifies what the class represents, which allows the class and package to change as needed. Fields can be added, removed, or converted through the optional serialConvert method.
public class ExampleSubClass extends ExampleSuperClass {
private static final String serialId = "xsub";
private static final String serialVersion = "1.0";
ExampleAggClass exNullAggClass = null;
String exString;
ExampleNonXCSerialClass nonXCSerialClass;
String exNum;
ExampleAggClass conAggClass;
public class RevisedExampleSubClass extends ExampleSuperClass {
private static final String serialId = "xsub";
private static final String serialVersion = "1.1";
ExampleAggClass exNullAggClass = null;
String newStringA;
String newStringB;
String exString;
Integer exNum;
ExampleNonXCSerialClass nonXCSerialClass;
String conAggString;
private void serialConvert(Converter converter, String fromVersion) {
if (fromVersion.equals("1.0")) {
converter.addField("newStringA", String.class, "new string!");
// intentionally not adding newStringB to see if warning is thrown
converter.convertField("exNum", new ConvertScript<String,Integer>(String.class, Integer.class) {
@Override
public Integer convert(String fromValue) {
return new Integer(fromValue);
converter.convertField("conAggClass", "conAggString", new ConvertScript<ExampleAggClass, String>(ExampleAggClass.class, String.class) {
@Override
public String convert(ExampleAggClass fromValue) {
return fromValue.getAggString();
// and then in some other class...
ExampleSubClass example = new ExampleSubClass();
System.out.println("Serializing class...");
XCObjectOutputStream xcoos = new XCObjectOutputStream(new FileOutputStream(file));
xcoos.writeObject(example);
xcoos.close();
System.out.println("Deserializing class...");
XCObjectInputStream xcois = new XCObjectInputStream(new FileInputStream(file), RevisedExampleSubClass.class);
RevisedExampleSubClass resc = (RevisedExampleSubClass) xcois.readObject();There is still a little more work to do to fully support arrays and collections, and I need to develop a rigorous test suite for it. But so far it's looking good.
Edited by: Skotty on Jul 18, 2010 5:31 PM -
I was wondering if I might get some help in debugging some timing issues for my serial data recording. Currently I am trying to create a loop that records data from a meter that outputs a comma-delimited string every 5 seconds. I have attached the VI that I am currently trying to debug.
The problem I am facing now is that sometimes I am not catching the correct string. It is catching either the tail end of a previous print, and then the read buffer is never cleared, so the data needed array cells 5, and 11 are not correct.
I was thinking that somehow I could simply wait on the data to arrive, do the reading etc, then wait 5 sec for the next bit of data -> or simply wait for the next complete string. If anyone has any suggestions please let me know, and code examples would be great.
Please let me know if you have any questions.
Thanks
Attachments:
test_serial.vi 167 KBHi Vessel,
I noticed another point: I suppose, your meter is configured to send this string every five seconds. Since the timing of your meter and the PC is not exactly the same, you have some timing interference effects, so that after a while your "Bytes at Port"- node executes, while the meter is sending the data (9600 Baud is not very fast). That's why you get only parts of the string.
A better approach to this problem would be to periodically call the "Bytes at Port"- node until the expected amount of Bytes is given back (if you expect a defined number of bytes). Or you read in all data you receive in a short time loop and check for some end-of-String condition, after this you can parse the String for the coma-separated values.
Perhaps I could help you, maybe you post your solution to the problem,
Dave
Greets, Dave -
HT1379 (A1211 McBook pro duo) MSG "clock is set to a date before 2008"
(A1211 McBook pro duo) MSG "...clock is set to a date before 2008..." I removed the CR2025 Batt and it tested 3.6v-dc. What should I look for next? The main Battery is a year old. Will a 'zap the pram' make a difference?
Apple/About This Mac/More Info/Hardware/Power/Battery Information - copy and paste the information here. Do not include any serial numbers.
-
After I install itunes on my windows 7 - 64 bit machine it will not reboot and I need to restore to a date before itunes was install. How do I fix this?
I'm having a very similar issue, paired with iTunes not being able to get online.
iTunes shows up in processes and then hangs at 17,000 K or so -- sometimes it will start up, but that (if it occurs) is a delay of literal hours.
Pretty meticulously went through all the 'cannot connect' trouble shooting, and have uninstalled, restarted, and then reinstalled every piece of apple software; issue is just as firm. Starting in safe mode or admin mode don't fix it; signing in as a different user doesn't fix it. -
How to verify that the user has changed table row data before db update
Hi all,
Iam using Oracle ADF with EJBs.
I have a single selection table that displays rows of data returned from a function of my data control.
The columns of my table are editable so that the user can change the data. The user selects a row, changes the data in one or more columns of the row and saves the data by means of a submit button. The code in the submit button, identifies the row of the corresponding iterator that the user clicked on and updates the data in the database (using the 'mergeEntity' function of the EntityManager)
Before saving the data, I want to put some logic to check whether the user has actually changed some data to avoid unnecessary updates in the database . But for this I need a technique to detect that the user has indeed changed some data in the table row.
One technique I have been using so far was to isolate the iterator row of the table and then query the corresponding row in the database table and compare their values.
Except from dummy, this technique is not efficient if the table contains many rows.
Moreover, in my case I have observed that on successive updates on the same row , the query on the database returns the new values (user changed values) and not the actual values contained in the database table. This means that when the user updates an iterator row the cached data affect also the results of the SELECT statement from the actual database table!!! Isn't this strange ?
Can somebody propose me a neat method to detect when the user has changed the the data of an iterator row ?Hey Alan,
The below solution seems overly complicated to me and can not be implemented without a custom screen and/or the use of JavaScript. Also, if your main concern is that a user may accidentally loose all their data because they closed the browser window or the session times out before they hit the save button then this solution does not help you.
There are a couple of simpler approaches you can take here:
# If the use of JavaScript is permissible you can hook into the windows 'onUnload' event, and pop-up a message box which gives the user the opportunity to cancel closing the window and save their case if they haven't already.
# Implement an autosave feature by hooking into one of events provided by web determinations. A simple (but rather naive) way of doing this would be to hook into the OnRenderScreenEvent and call save on the interview session every time the event fires. This guarantees that all the data the user has submitted will aways automatically be saved, thereby removing the need to make sure the user manually saves their data before closing the browser.
Automatically making Web Determinations close a browser window has to be done using JavaScript. However, doing so means that a) it won't work for people who turn off JavaScript, which is commonly done for accessibility reasons b) you'll likely run afoul of the browser's security mechanism (they generally won't let you close a window that you didn't open and some really don't like you doing that at all).
Thanks,
Kristy -
How can i read the text files and buffer the data in Vector?
hi. I have been running into this problem for days, but with no luck and losing right direction.
The problem is : I am trying to read a text file and buffer the data into a
Queue for each user.
the sample text file is as below:( 1st column is timestamp, 2nd is user_id, 3rd is packet_id, 4th is packet_seqno, 5th is packet_size)
0 1 1 1 512
1 2 1 2 512
2 3 1 3 512
3 4 1 4 512
4 5 1 5 512
5 6 1 6 512
6 7 1 7 512
7 8 1 8 512
8 9 1 9 512
9 10 1 10 512
10 1 2 11 512
11 2 2 12 512
12 3 2 13 512
13 4 2 14 512
14 5 2 15 512
15 6 2 16 512
16 7 2 17 512
17 8 2 18 512
18 9 2 19 512
19 10 2 20 512
20 1 3 21 512
21 2 3 22 512
22 3 3 23 512
23 4 3 24 512
24 5 3 25 512
25 6 3 26 512
26 7 3 27 512
27 8 3 28 512
28 9 3 29 512
29 10 3 30 512
30 1 4 31 512
31 2 4 32 512
32 3 4 33 512
33 4 4 34 512
34 5 4 35 512
35 6 4 36 512
36 7 4 37 512
37 8 4 38 512
38 9 4 39 512
39 10 4 40 512
40 1 5 41 512
41 2 5 42 512
42 3 5 43 512
43 4 5 44 512
44 5 5 45 512
45 6 5 46 512
46 7 5 47 512
47 8 5 48 512
48 9 5 49 512
49 10 5 50 512
50 1 6 51 512
51 2 6 52 512
52 3 6 53 512
53 4 6 54 512
54 5 6 55 512
55 6 6 56 512
56 7 6 57 512
57 8 6 58 512
58 9 6 59 512
59 10 6 60 512
60 1 7 61 512
61 2 7 62 512
62 3 7 63 512
63 4 7 64 512
64 5 7 65 512
65 6 7 66 512
66 7 7 67 512
67 8 7 68 512
68 9 7 69 512
69 10 7 70 512
70 1 8 71 512
71 2 8 72 512
What I wanna do is to read all the data above and buffer them in a queue for each user( there are only 10 users in total).
I already created a class called Class packet:
public class packet {
private int timestamp;
private int user_id;
private int packet_id;
private int packet_seqno;
private int packet_size;
/** Creates a new instance of packet */
public packet(int timestamp,int user_id, int packet_id,int packet_seqno, int packet_size)
this.timestamp = timestamp;
this.user_id=user_id;
this.packet_id=packet_id;
this.packet_seqno=packet_seqno;
this.packet_size=packet_size;
}then I wanna to create another Class called Class user which I can create a queue for each user (10 users in total) to store type packet information. the queue for each user will be in the order by timestamp.
any idea and sample code will be appreciated.Doesn't sound too hard to me. Your class User (the convention says to capitalize class names) will have an ArrayList or Vector in it to represent the queue, and a method to store a Packet object into the List. An array or ArrayList or Vector will hold the 10 user objects. You will find the right user object from packet.user_id and call the method.
Please try to write some code yourself. You won't learn anything from having someone else write it for you. Look at sample code using ArrayList and Vector, there's plenty out there. Post in the forum again if your code turns out not to behave. -
I found this (TS3579: If the wrong date or time is displayed in some apps on your Mac Learn about If the wrong date or time is displayed in some apps on your Mac) useful because I did not know about the effect of typing in data and that you could only drag to rearrange the data. I had typed in data before and this had caused problems but restoring defaults did not cause correct dates to show up in Finder.
It sounds like there are a couple things going on here. First check if you have a successful install of SQL Server, then we'll figure out the connection issues.
Can you launch SQL Server Configuration Manager and check for SQL Server (MSSQLSERVER) if default instance or SQL Server (other name) if you've configured your instance as a named instance. Once you find this, make sure the service is started.
If not started, try to start it and see if it throws an error. If you get an error, post the error message your hitting. If the service starts, you can then launch SSMS and try to connect. If you have a default instance, you can use the machine
name in the connection dialog. Ex: "COWBOYS" where Cowboys is the machine name. However, if you named the SQL Server instance during install, you'll need to connect using the machine\instance format. Ex: COWBOYS\Romo (where Romo
is the instance name you set during install).
You can also look at the summary.txt file in the SQL Server setup error logs to see what happened on the most recent install. Past install history is archived in the log folder if you need to dig those up to help troubleshoot, but the most
recent one may help get to the bottom of it if there is an issue with setup detecting a prior instance that needs to be repaired.
Thanks,
Sam Lester (MSFT)
http://blogs.msdn.com/b/samlester
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click
"Mark as Answer" and
"Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread. -
I had Adobe Acrobat Serial loaded before the hard drive crashed on my old PC. I have tried to download Acrobat 9 on my new PC, but always get the message “This is not a valid serial number”.
I had Adobe 9 Standard on the old. But what downloads from the page http://helpx.adobe.com/acrobat/kb/acrobat-8-9-product-downloads.html is Adobe 9 Pro. Perhaps this Pro version is the problem.
Anyway, can you point me to a way to install Adobe on my new PC?You can try Download Adobe CS5 Free Trials – All Direct Links without Akamai | ProDesignTools.
-
Put Date Before Header Line in Receiver FCC
Hi,
I have to create a csv file with format :
Date : dd/mm/yyyy to dd/mm/yyyy
PRODUCT_CODE,NAME,ADDRESS
123,ABC,xyz
123,ABC,xyz
123,ABC,xyz
123,ABC,xyz
123,ABC,xyz
How should i achieve putting the date before header line?
What should be my target structure format?
What parameters to enter in receiver FCC?Hi,
have you tried..
Have you tried:
(http://help.sap.com/saphelp_nw04/helpdata/en/e3/94007075cae04f930cc4c034e411e1/frameset.htm)
● NameA.enclosureSign
Specify a string that acts as a text delimiter.
Text enclosed by such delimiters is transferred to the target structure unchanged, although the default setting is to remove all text delimiters. Separators within such texts are ignored.
This parameter is optional. The default setting is an empty value (no text delimiter).
● NameA.enclosureSignEnd
If the text delimiters for the beginning and end of the text are different, specify the text delimiter for the end of the text here.
If you do not make an entry here, the entry from NameA.enclosureSign is used.
● NameA.enclosureSignEscape
Specify a string that replaces the text delimiter if it occurs within a text that it delimits.
When the text is transferred the string is replaced by the value specified in NameA.enclosureSign .
● NameA.enclosureSignEndEscape
Specify a string that replaces the text delimiter for the end of the text if it occurs within a text that it delimits.
When the text is transferred the string is replaced by the value specified in NameA.enclosureSignEnd.
● NameA.enclosureConversion
To remove the delimiter upon transfer, or to replace it with escape characters, enter YES. This is the default value.
To transfer the characters unchanged enter NO.
Note
If you specify xml.enclosureSign= and xml.enclosureSignEsc=, text enclosed in quotation marks is transferred unchanged and the quotation marks are removed.
If the escape character for a quotation mark () occurs in the text itself, it is replaced by the quotation mark during the transfer.
Thanks,
Vijaya. -
Date Validation - End date before Start date
This may be a very simple validation but I seem to be having trouble. I've got a form which requires a date range to be selected (Date Picker fields)...a Start date, and an End date.
I've created a Function Returning Boolean validation with the code as:
begin
if :P1_END_DATE < :P1_START_DATE then
return false;
else
return true;
end if;
end;This works 99%, except when the date range spans years.
For example, when I select '21-Dec-2010' in the start date and '4-Jan-2011' in the end date. The validation fails, and thinks the end date is before the start date.
Do I need to compare the year part of the date, before doing the rest? Or is the '<' not suited for this sort of check?
Edited by: djston on Dec 20, 2010 12:13 PMSorry, false alarm, it looks like I had my logic a little backwards :)
-
Hi,
I have CURRENT DAY variable and i want to create one more variable which gives the Date before 30 days.
Is there any STD variable which gives the date before 30 days .Please tell me.
I have created one variable with Customer exit processing type and i need to develop code for this. Can anybody provide code how we will get date(dd/mm/yyyy) before 30 days .I have created variable with name "Z_CVAR". Please help me on this.use 0date variable to get the system date ... which is the SAP standard variable which pics the sy-datum.
Next restrict the KF with the 0date and right click on the 0date and click on offset and set the off set for the varaible as -30.
which gives the value -30 days.
If not as suggested in the earlier post -- create a z variable with replacement path -customer exit -- write the code ... in the code itself write the logic to get the -30 days
IF i_step = 2.
CASE i_vnam.
WHEN 'ZCURDAY-30'.
CLEAR: l_s_range.
l_s_range-low = sy-datum -30.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
ENDCASE.
ENDIF.
regards
KP
Maybe you are looking for
-
Follow Up to iMac G5 Crash n Burn
If you go here you will read of an issue my wife was having. We thought it was resolved and this is a follow up to that/those issues. In the end it was a defective hard drive. Which Apple replaced after confirming what Diskwarrior® had identified aft
-
Conversion of Data between 3.1 to 7.0
Hello Everybody, I have a need to convert a large volume of data from BW 3.* to 2004s. Due to the volume of data what would be the best conversion practice. 1. I create a RFC between the system and create export data source out of 3.* box and extract
-
How to configure work flow for Material Master creation or change?
-
How to resubmit the form when back button pressed
Hi, In my application, iam implementing searching, when i submitting the form, i got some records and i navigated all the results through next and previous buttons. Problem occurs when i clicked on back button, it is showing "page expires and asking
-
Deletion of Characters in String
Hi I having a problem. Below shows String s = "Hello"; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != 'e' && s.charAt(i) != 'o') { System.out.print(s.charAt(i)); If I want to let user to key in the string and the program will be able to de