TCP Callback on Newline Character
I have a TCP connection to a device that sends its short message (< 100 characters) in chunks. Unfortunately these chunks seem to be random. I am having some difficulty tokenizing the data and getting it into five floats. Is there any way I can make this TCP callback fire only when a newline character is received, or a better method of putting the message together? I'm going to be dealing with much larger TCP messages for other devices, so it will be good to get this issue resolved on a small scale problem.
For whatever reason, my logic is allowing incomplete messages to be tokenized. The message leads with BARO and ends with \r\n.
receiveBuf[dataSize] = '\0';
if (strstr(receiveBuf,"\n") == NULL)
strcpy(Vaisala.Message, receiveBuf);
else
if ((strlen(Vaisala.Message) + strlen(receiveBuf) < 100) || (strstr(receiveBuf,"BARO") == NULL))
strcat(Vaisala.Message, receiveBuf);
Vaisala.Message[strlen(Vaisala.Message) - 2] = '\0';
token = strtok(Vaisala.Message, "\t");
token = strtok(NULL, "\t");
Vaisala.Barometric = atof(token);
token = strtok(NULL, "\t");
token = strtok(NULL, "\t");
Vaisala.DryBulb = atof(token);
token = strtok(NULL, "\t");
token = strtok(NULL, "\t");
Vaisala.WetBulb = atof(token);
token = strtok(NULL, "\t");
token = strtok(NULL, "\t");
Vaisala.Dewpoint = atof(token);
token = strtok(NULL, "\t");
token = strtok(NULL, "\t");
Vaisala.RH = atof(token);
else
memset(Vaisala.Message, '\0', 100);
Michael Chadwell
Department of Engine and Vehicle R&D
Southwest Research Institute
I found a workaround that I don't like.
1. If the message starts with B, start a new string.
2. If the message does not have \n, concatenate the message.
3. If the message has a \n, parse the data.
Seems to work well but I won't always have such fixed strings so I'd like a callback that fires when the \n is received.
case TCP_DATAREADY:
if ((dataSize = ClientTCPRead (VaisalaTCPConnectionHandle, receiveBuf, dataSize, 1000)) < 0)
// Error
else
receiveBuf[dataSize] = '\0';
if ((strstr(receiveBuf,"\n") == NULL) && (receiveBuf[0] == 'B'))
strcpy(Vaisala.Message, receiveBuf);
else if (strstr(receiveBuf,"\n") == NULL)
strcat(Vaisala.Message, receiveBuf);
else
if ((strlen(Vaisala.Message) + strlen(receiveBuf) < 100) || (strstr(receiveBuf,"BARO") == NULL))
strcat(Vaisala.Message, receiveBuf);
Vaisala.Message[strlen(Vaisala.Message) - 2] = '\0';
token = strtok(Vaisala.Message, "\t");
token = strtok(NULL, "\t");
Vaisala.Barometric = atof(token);
token = strtok(NULL, "\t");
token = strtok(NULL, "\t");
Vaisala.RH = atof(token);
token = strtok(NULL, "\t");
token = strtok(NULL, "\t");
Vaisala.Dewpoint = atof(token);
token = strtok(NULL, "\t");
token = strtok(NULL, "\t");
Vaisala.DryBulb = atof(token);
token = strtok(NULL, "\t");
token = strtok(NULL, "\t");
Vaisala.WetBulb = atof(token);
else
memset(Vaisala.Message, '\0', 100);
// Process data here
break;
Michael Chadwell
Department of Engine and Vehicle R&D
Southwest Research Institute
Attachments:
Serial.jpg 105 KB
Similar Messages
-
How to escape newline character(nl) in file content conversion parameter?
Hi Experts,
How to escape newline character(nl) in file content conversion parameter?
For example:
field1field2field3
field4field5field6
Means Item is splitted in two lines.
I want to SKIP new line character
and to collect all SIX fields.
What will be the file content conversion parameter?
Thanks in Advance..........Hi,
as far as i know there is nothing in the standard. But the question is why dont you combine at mapping the fields into only structure?
Regards,
Udo -
File format for newline character
Hi there, I have a scenario to do. From IDOC to flat file. I receive a number of idocs and must convert them into a flat file. Each idoc must start on a new line. Each line represents a new record. I have done this and it works fine. But now the system reading the flat file is having trouble with the newline character. Im using ABAP mapping to create the flat file and the newline characters I tried are
l_crlf(2) VALUE %_cr_lf
l_crlf(1) VALUE %_NEWLINE
Lest say I open the flatfile in MS Word and do a character count it shows as 100 char's but on there system it shows as 101. It has something to do with the file format..
Does anyone know how to fix this?
Thanx,
JanIt turnes out that their file encoding was not the same as ours so I just changes the file type brom binary to text and set the encoding to UTF-8
Thanx,
Jan -
How to remove the newline character at the start in the attachment ?
Hi All,
I have been trying to attach a .dat file generated at an external source and send it as an attachment by mail using UTL_SMTP, all things are working but the .dat file which comes attached in mail contains a newline character i.e. chr(10) at the start line and the contents of the file are written from second line onwards. Below is some part of the code which deals with read/write of attachment of mail to be sent.
Can anyone help me on this, is something to be changed in this code??
UTL_SMTP.write_data(c,
'Subject' || ': ' || P_SUBJECT || UTL_TCP.crlf);
UTL_SMTP.write_data(c,
'MIME-Version: 1.0' || UTL_TCP.crlf || -- Use MIME mail standard
'Content-Type: multipart/mixed;' || UTL_TCP.crlf ||
' boundary="-----SECBOUND"' || UTL_TCP.crlf ||
UTL_TCP.crlf);
UTL_SMTP.write_data(c,
'-------SECBOUND' || UTL_TCP.crlf ||
'Content-Type: text/plain;' || UTL_TCP.crlf ||
'Content-Transfer_Encoding: 7bit' || UTL_TCP.crlf ||
UTL_TCP.crlf);
UTL_SMTP.write_data(c, UTL_TCP.crlf || l_text);
UTL_SMTP.write_data(c, UTL_TCP.crlf);
UTL_SMTP.write_data(c, UTL_TCP.crlf);
UTL_SMTP.write_data(c,
'-------SECBOUND' || UTL_TCP.crlf ||
'Content-Type: text/plain;' || UTL_TCP.crlf ||
' name="/inetpub/wwwroot/Novation_Merge/FS_Extract.dat"' ||
UTL_TCP.crlf ||
'Content-Transfer_Encoding: 8bit' || UTL_TCP.crlf ||
'Content-Disposition: attachment;' ||UTL_TCP.crlf || ' filename="' || p_description ||
TO_CHAR(SYSDATE, 'DD-MON-YYYY') || '.dat"' ||
UTL_TCP.crlf || UTL_TCP.crlf ||UTL_TCP.crlf);
BEGIN
l_filehandle := UTL_FILE.fopen('c:\temp',
'FS_Extract.dat',
'r',
32767);
LOOP
UTL_FILE.GET_LINE(l_filehandle, l_buffer, 32767);
UTL_SMTP.write_data(c, l_buffer || UTL_TCP.crlf);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
UTL_FILE.fclose(l_filehandle);
UTL_SMTP.write_data(c, '-------SECBOUND--');
UTL_SMTP.close_data(c);
UTL_SMTP.quit(c);
EXCEPTION
WHEN UTL_SMTP.transient_error OR UTL_SMTP.permanent_error THEN
BEGIN
UTL_SMTP.quit(c);
EXCEPTION
WHEN UTL_SMTP.transient_error OR UTL_SMTP.permanent_error THEN
NULL;
-- When the SMTP server is down or unavailable, we don't have
-- a connection to the server. The quit call will raise an
-- exception that we can ignore.
END;
RAISE_APPLICATION_ERROR(-20000,
'Failed to send mail due to the following error: ' ||
SQLERRM);
END;
Thanks,
-AmolAs I recall, a single blank line serves as separator between Mime Header and Mime Body.
This code..
UTL_SMTP.write_data(c,
'-------SECBOUND' || UTL_TCP.crlf ||
'Content-Type: text/plain;' || UTL_TCP.crlf ||
' name="/inetpub/wwwroot/Novation_Merge/FS_Extract.dat"' ||
UTL_TCP.crlf ||
'Content-Transfer_Encoding: 8bit' || UTL_TCP.crlf ||
'Content-Disposition: attachment;' ||UTL_TCP.crlf || ' filename="' || p_description ||
TO_CHAR(SYSDATE, 'DD-MON-YYYY') || '.dat"' ||
UTL_TCP.crlf || UTL_TCP.crlf ||UTL_TCP.crlf); ..generates 2 blank lines after the Mime Header.
Remove the last CRLF and see if that does the trick. -
External table and newline character
I have an external table which is just a csv file, records delimited by newline and fields terminated by ','. However, the last column has a newline character appended to it. Is there an option in the external table syntax which will trim this?
Try setting 'REJECT ROWS WITH ALL NULL FIELDS'
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch12.htm#1011062 -
TCP Callback function passing data to teststand
Hi,
I'm trying to pass data via a TCP Callback function to teststand using the TCP steptype that I downloaded from Ni.
When I open a connection, container data is passed to the dll on which it creates a connection, the dll in part creates a TCP Callback function.
The handle obtained from the connection is then passed back through the container data, and the dll returns back to the sequence editor which will execute the next steps.
The problem is that when the TCP Callback function gets an TCP_READY event it can not pass data to TestStand because it can not access the container data.
How can this TCP Callback function pass/alter data to/in Testand?
Thank you...Yes ThiCop,
That's exactly what I want to establish!
Here is the example code:
//Function needed by the TCP functions
int CVICALLBACK MsgHandler (unsigned handle, int event, int error, void *callbackData)
char receiveBuf[256] = {0};
char displayBuf[7] = {0};
char * tempLookup;
int dataSize = sizeof (receiveBuf) - 1;
switch (event)
case TCP_CONNECT:
break;
case TCP_DISCONNECT:
break;
case TCP_DATAREADY:
if ((dataSize = ClientTCPRead (handle, receiveBuf, dataSize, 1000)) > 0)
// Send data from receiveBuf to a variable in teststand ????
// TS_PropertyGetValString (HandleObject, NULL, "Step.Result.Data", 0, &tempLookup);
// TS_PropertySetValString (HandleObject, NULL, tempLookup, 0, receiveBuf);
else
receiveBuf[dataSize] = '\0';
break;
return 0;
void __declspec(dllexport) TX_TEST TCPConnectF(tTestData * testData, tTestError * testError)
int error = 0;
int TCPerror;
double Port;
double Timeout;
char *HandleLookup;
char *ServerAdd;
char *CallbackData;
ErrMsg errMsg = {'\0'};
ERRORINFO errorInfo;
tsErrChk (TS_PropertyGetValString (testData->seqContextCVI, &errorInfo, "Step.Result.Handle", 0, &HandleLookup));
tsErrChk (TS_PropertyGetValNumber (testData->seqContextCVI, &errorInfo, "Step.Result.Port", 0, &Port));
tsErrChk (TS_PropertyGetValString (testData->seqContextCVI, &errorInfo, "Step.Result.IP", 0, &ServerAdd));
tsErrChk (TS_PropertyGetValNumber (testData->seqContextCVI, &errorInfo, "Step.Result.Timeout", 0, &Timeout));
tsErrChk (TS_PropertyGetValString (testData->seqContextCVI, &errorInfo, "Step.Result.Data", 0, &CallbackData));
TCPerror = ConnectToTCPServer (((unsigned int *) &ConnectionHandle), ((unsigned int) Port), ServerAdd, MsgHandler, 0, Timeout);
if (TCPerror != 0)
//Get TCP Error Message
sprintf(errMsg,"%s",GetTCPErrorString ( TCPerror ));
error = TCPerror;
goto Error;
tsErrChk (TS_PropertySetValNumber (testData->seqContextCVI, &errorInfo, HandleLookup, 0, ((double) ConnectionHandle)));
Error:
// FREE RESOURCES
CA_FreeMemory(HandleLookup);
CA_FreeMemory(ServerAdd);
// If an error occurred, set the error flag to cause a run-time error in TestStand.
if (error < 0)
testError->errorFlag = TRUE;
testError->errorCode = error;
testData->replaceStringFuncPtr(&testError->errorMessage, errMsg);
return; -
Hi,
How can i introduce a newline character while displaying a string using string functions in a report..
My requirement is, i need to replace a particular character with a newline character in a string using replace function
Can anyone help me
Thanks in advance..Hi,
Try this,
REPLACE(Table.ColumnName, 'StringOrCharacterToReplace', '[br]')
*replace [ and ] with < and > in br tag. Change the data format of the column to HTML
Rgds,
Dpka -
Is is standard for JSP to output every newline character it sees?
I've encountered a very annoying problem using JSP. It seems JSPC outputs every newline character it sees in the JSP page -- even if it is after a JSP comment or JSP directive. Look at the sample JSP at the bottom: it will output 4 blank lines (3 from comments + 1 from directive) before it prints "JSP Body Line 1". Granted, this is not a big problem if the content is HTML and will be viewed in a browser. However, my content has to be plain text because the client in my case is not always a browser.
I've tested this on both JRun and TomCat. Same results. I don't understand why is this, because intuitively the JSP designer would not have meant to output those blank lines, right? I'm wondering if this is really an "official" behavior prescribed by the JSP standard, or just an oversight in JRun and TomCat? Could any expert help me verify this in JSP standard (by the way, which one is the official document that spells out the JSPC implementation?) or anyone help me test it in other App Server (e.g. WebLogic, WebSphere, etc.) which I don't have access to? Your help is greatly appreciated!
======= Sample JSP code ========
<%-- JSP Comment Line 1 --%>
<%-- JSP Comment Line 2 --%>
<%-- JSP Comment Line 3 --%>
<@ page contentType="text/plain" %>
JSP Body Line 1
JSP Body Line 2
...The truth is, newlines (as far as HTML or most XML is concerned) are just any old kind of whitespace. An extra line or two isn't a major problem, the only time this will really cripple you is if you want to insert scriptlets above the <?xml...> line.
-
How to remove a newline character from a column
hi all...
i have a column in a table in which some of the datas contain a newline character at their last.
i need to remove those newline characters.
for example.... a data is
'abcd
(notice the end of the quotation).....i need to get the data as...'abcd'
plss help me...
thanks in advance..thanks for ur reply...
i got your point..but here what you have done is....u have inserted a particular character set in between 'abcd' and 'xyz' and afetr that just replaced those character set by null....
but in my case the problem is a bit different...
the datas are already present and what i have to do is to remove the newline spaces from the end of the datas.
select replace(column_name,'<what shall i put here>',null) from table_name;
in your example...that is 'chr(10)'...but in my case its a newline character.... -
NewLine Character in the String received from Interactive Adobe Form
Hello Experts,
Following is the issue we have with interactive Adobe Form
We have a text area within the form. User enters the text in multiple lines in this text area.
We are calling a backend function module designed in SE37 that accepts and process the data from the adobe form. We are also processing the string data user enters in the text area.
When we receive the string from the form, the newline character within the string is displayed as '#' in the debugger. We tried splitting this string using cl_abap_char_utilities=>newline and cl_abap_char_utilities=>cr_lf but NO luck. Though in the debugger we see cl_abap_char_utilities=>newline as '#' in the debugger and also '#' is present within the string, for some reason when string is processed to find cl_abap_char_utilities=>newline, we can find/locate it.
Because ABAP code is not able to identify the newline character within the string received from Adobe form, we are not able to maintain the formatting of the string as it was entered in the form.
Any help to resolve this issue is appreciated.
Thanks in Advance.
Regards,
BhushanHi Bhushan,
I was going through your issue, and I feel this is something you can do with scripting. Basically you should read whole string and find the new line character and replace with a space or comma, as per your requirment.
Do like following:
In the exit event of the field select java script and write following code:
var strng = this.rawValue;
strng.replace(/\n/g, " ");
above im reaplcing new line with a space.
I think it should work I have not tested it. Pls update if you test it .
Regards,
Ravi.D -
How can I remove the newline character only from the very end
of a string? (Note there are several newline characters within the
string). Thanks!How long is the string and roughly how many newline
characters are there? One way, although kinda funky, would be to
convert the newline-delimited list to an array, and then convert it
back. See below. -
Inserting newline character in header in messageformat class
i've to print 5 lines in header.i've created header using messageformat class.But the newline character not working.(paper size:width=4in)please help.
Thanx for ur reply.
i've to print a jtable.i couldn't change font size and also no. of lines for headers.i want the font size same as that of the footer.
here is my code
jtable.print(printmode,headerformat,footerformat,null, false, null) -
Hi All,
I am writing my output to a file .....
I want to write the subsequent outputs to the same file accompanied by newline character...
How do i do that?Use a PrintStream (or its equivalent Writer) and let the println()
method do its job, i.e. it will print the correct newline combination
depending on your platform. If you must do it yourself have a look at
the System.getProperty("line.separator") property.
kind regards,
Jos -
Getting the newLine character when deleting a line...
I have a JTextArea that has a custom DocumentListener added. What I want is to be notified when the user hits enter for a new line and be notified when the user removes a line. Getting the newLine when the user hits enter is easy enough, however the reverse is not true. Whenever backspace is pressed it gets the same removeLine character, which is not what I want, because a backspace is not a removeLine( or newLine) character. Here is my code so far...
public void insertUpdate(DocumentEvent e){
Document d = e.getDocument();
try {
String s = d.getText(e.getOffset(), e.getLength());
System.out.println("got a line");
} catch (BadLocationException e2) {
e2.printStackTrace();
public void removeUpdate(DocumentEvent e){
Document d = e.getDocument();
try {
String s = d.getText(e.getOffset(), e.getLength());
if(s.equals("\n"))
System.out.println("removed a line");
} catch (BadLocationException e2) {
e2.printStackTrace();
};It's in the removeUpdate that my code is flawed. Can anyone stear me in the right direction?What for?By definition when you have a problem, you don't know what the problem or solution is. So you post a SSCCE showing what you've attempted so far so that we can see the problem you are describing.
Since you also don't know how to ask a very clear question. The SSCCE help in describing the problem. Maybe it won't help in this case, but you don't know that before hand. So you get in the habbit of always posting a SSCCE.
You talk about removing a line, but I don't know what that means. What happens if you data in a text area like:
123
456
789
To me removing a line means removing "123\n" to that the entire line is removed from the file. Or what happens if you select 3 and 7 with the mouse and then use the "Delete" key? Did you remove 1 line or 2 lines. Are you trying to count the number of "\n" characters that have been removed. Or do you only care about the backspace key because that was a concious decision or did you just not think about all the other possibilities of how text can be removed from a Document?
So as you can see you question is not a simple and straight forward as you thought. Without a SSCCE to clarify exactly what you are doing we can only provide half an answer.
You can find the answer by reading the Swing tutorial. Maybe the section on Key Bindings, if you just want to know when a certain key was pressed. Or maybe the section on a DocumentFilter if you want to know what text has actually been added or removed from the Document (before it happens). -
Loading data having newline Character
Hello Everyone,
I am trying to load a .csv file to a single table using SQL Loader.
Sql*loader 11.2.0.1.0
Operating system: Windows 7
My control file is as follows
LOAD DATA
INFILE 'C:\Test.csv'
Into table TEST
Fields terminated by "," optionally enclosed by '"'
TRAILING NULLCOLS
name ,
group,
description
Test.csv File is as follows
Sam, Developer, "This is test data,This is Test data. Tis is test data this is test data,Tis is test data
Test1Test2
Test1 Test2
", Anna, PM,"This is testdata
This is test data@Test
this is test data
newline character Test
"newline character Test:Test Data Test data""
My log file gives me an error
Record : Rejected - Error on table TEST, column DESCRIPTION.
Initial enclosure character not found
Record : Rejected - Error on table TEST, column DESCRIPTION.
second enclosure string not present
Help Please!Looks like you have syntax errors :
Cause: A mandatory initial enclosure delimiter was not present. Either it is missing on the current field or the previous field is missing an identical closing delimiter.
Action: Supply the missing delimiters.
Cause: The logical end of record or the end of a LOBFILE was reached before a second enclosure delimiter was found.
Action: Correct the datafile to include the missing delimiter.
Regards
Maybe you are looking for
-
CRVS2010 Beta - Crystal Report Installation problem
Hello, I have visual studio 2010 professionnal edition (Version 2010 10.0.30319.1RTMrel). (French edition) I would like to install and use Crystal Report, so: - I dowloaded the Crystal report setup (cr4vs2010.exe). - After installing the setup, I wan
-
Same as question. On two different URL sites, the download PDF comes up black. I would include the screen shot of the black pdf, but I do not see where I can add this to my question
-
One of the folders of Robo Help Project Manager is listed twice in Windows Explorer.
Hello Everybody, One of the folders of Robo Help Project Manager is listed twice in Windows Explorer. One has all the subfolders and topics of it and the other has all the subfolders but not the topics. How did I get into this kind of situation? Why
-
Hi! Is it possible to change some key in HashMap? I mean: I've got HashMap<String,Object> and I want to update String (key). There is one solution possible: to make a temporary object with value, remove the whole row in HashMap and then add a new row
-
Dear SDN Experts & MM Gurus, I had run automatic vendor evaluation in back groung . I need your experities in the following queries . 1. system is giving messsage weighing Key doesnot exists for the purchase organization & in overall score in Me62 or