Not able to preserve bytes values>127 with ReadExisting(); - visual-c++

I read bytes from a microcontroller in VC++2010(that i dont know absolutely but i must use as in lack of someone else) using SerialPort and on DataReceived event.
private: System::Void serialPort1_DataReceived(System::Object^ sender,
System::IO::Ports::SerialDataReceivedEventArgs^ e)
{
String^mystr;
mystr = serialPort1->ReadExisting();
I need raw data but everything >0x7F looks changed to 0x3F.
in the watch window mystr[3]=0x3F,despite i sent 0x80;
Why are some data lost?I expect that a raw byte could be converted in a char ,maybe an impossible to print char,but without altering the data.
Is there any way to have an array of raw data instead?
Thanks

Related

Get multiple sensor values with http.GET()

I have a php file in my website which returns sensor reading. I had been fetching this reading and displaying in my Serial monitor using the below code
http.begin("http://<MYWEBSITE>/fetch_sensor.php");
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
SensorReading = payload.toInt();
Serial.print("Sensor Reading=");
Serial.print(SensorReading);
Serial.println();
}
Now I have updated my php file to return readings of multiple sensors. The readings are returned seperated by commas like 23,66,82,100
I am looking to update my code so that the readings returned by the php file is assigned as SensorReading1, SensorReading2, SensorReading3 etc.
Seeking help from experts..
Thanks!!
You need to split your incoming string into separate strings, and then display each one. There are a few ways of splitting a string: https://arduino.stackexchange.com/questions/1013/how-do-i-split-an-incoming-string

<SOLVED> Using/Manipulate String Variable in Arduino SoftwareSerial (iSerial.println(String_Variable))

As per subject, how do I to manipulate the string passed through SoftwareSerial Print/Println function? The reason why is I tried to make the URL parameter dynamic in order to access different webpages.
*Note: The code snippet below are working fine if without using String variable
// This is working fine
SoftwareSerial iSerial(28, 29);
iSerial.println("AT+HTTPPARA=\"URL\",\"http://website.com/data1.php\"");
delay(1000);
Serial.write(iSerial.read());
// This is not working
SoftwareSerial gprsSerial(28, 29 );
Int inputNumber;
String S1 = "AT+HTTPPARA=\"URL\",\"http://website.com/";
String S2 = String(inputNumber) + "data.php\"";
String_Variable = S1+S2;
iSerial.println(String_Variable);
delay(1000);
Serial.write(iSerial.read());
*Working means able to access the webpage via simcard using SIM900 (AT+HTTPPARA)
I even tried converting the string to array using malloc() and toCharArray() but it is still not working when I use the SoftwareSerial print function.
I'm new to Arduino. Kindly advise. Thanks! :)

how to get access and read message_t data tinyos

hello every one i want to ask you if you know a way to extract data from message_t
in the oldest version of TinyOs there are TOS_Msg and TOS_MsgPtr but in message_t i could't find a way please help me
and i want to know if there is any data type to store data like table or array list
typedef nx_struct message_localization{
nx_uint8_t NodeId;
bool ancre_nature;
nx_uint8_t x_coordinate;
nx_uint8_t y_coordinate;
x_uint8_t energie_transmited;
} message_localization_t;
The Packet interface has a command getPayload which does want you want:
command void *getPayload(message_t *msg, uint8_t len);
See the documentation for more information.
To access the data field, you may do as follows:
message_t msg;
message_localization_t *payload =
(message_localization_t *)call Packet.getPayload(
&msg, sizeof(message_localization_t));
payload->x_coordinate = x;
payload->y_coordinate = y;
/* and so on */
The same command is for convenience included in interfaces Send and AMSend. Packet and AMSend are provided by the ActiveMessageC configuration.

How do i read and edit huge excel files using POI?

I have a requirement to do the following
1)Copy a huge excel file 1400*1400 and make a copy.
2)Read the copied file and add new columns and rows and also edit at the same time.
3)This is going to be a standalone program and not on a server. I have limitations of having low memory footprint and fast performance.
I have done some reading and have found the following
1)There is no API to copy sucg a huge file
2)SXSSF can be using for writing but not for reading
3)XSSF and SAX (Event API) can be using for reading but not for editing.If i tried to read and store as objects again i will have a memory issue.
Please can you help on how i can do this?
Assuming your memory size is large enough to use XSSF/SAX to read and SXSSF to write, let me suggest the following solution.
1) Read the file using XSSF/SAX. For each row, create an object with the row data and immediately write it out into a file using ObjectOutputStream or any other output format you find convenient. You will create a separate file for each row. And there will only be 1 row object in memory, because you can keep modifying the same object with each row's data.
2) Make whatever modifications you need to. For rows that need to be modified, read the corresponding file back into your row object, modify as needed, and write it back out. For new rows, simply set the data in your row object and write it out to a new file.
3) Use SXSSF to reassemble your spreadsheet by reading 1 row object file at a time and storing it in your output spreadsheet.
That way, you will only have 1 row in memory at a time.
If there is much data due to which 'Out of Memory' or 'GC overlimit exceeded' occurs and if memory is a problem the data can be initially parsed to a xml file. The excel sheet can be replaced with the xml file so that memory usage will be minimum.
In excel the sheets are represented as xml. Using java.util.zip.ZipFile each entries can be identified. The xml for the sheet can be replaced with the parsed xml so that we get the expected data in excel sheet.
Following class can be used to create xml files:
public class XmlSpreadsheetWriter {
private final Writer _out;
private int _rownum;
public XmlSpreadsheetWriter(Writer out){
_out = out;
}
public void beginSheet() throws IOException {
_out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">" );
_out.write("<sheetData>\n");
}
public void endSheet() throws IOException {
_out.write("</sheetData>");
_out.write("</worksheet>");
}
public void insertRow(int rownum) throws IOException {
_out.write("<row r=\""+(rownum+1)+"\">\n");
this._rownum = rownum;
}
public void endRow() throws IOException {
_out.write("</row>\n");
}
public void createCell(int columnIndex, String value, int styleIndex) throws IOException {
String ref = new CellReference(_rownum, columnIndex).formatAsString();
_out.write("<c r=\""+ref+"\" t=\"inlineStr\"");
_out.write(" s=\""+styleIndex+"\"");
_out.write(">");
_out.write("<is><t>"+value+"</t></is>");
_out.write("</c>");
}
public void createCell(int columnIndex, double value, int styleIndex) throws IOException {
String ref = new CellReference(_rownum, columnIndex).formatAsString();
_out.write("<c r=\""+ref+"\" t=\"n\"");
_out.write(" s=\""+styleIndex+"\"");
_out.write(">");
_out.write("<v>"+value+"</v>");
_out.write("</c>");
}
public void createEmptyCell(int columnIndex, int styleIndex)throws IOException {
String ref = new CellReference(_rownum, columnIndex).formatAsString();
_out.write("<c r=\""+ref+"\" t=\"n\"");
_out.write(" s=\""+styleIndex+"\"");
_out.write(">");
_out.write("<v></v>");
_out.write("</c>");
}
}
If memory is the problem with processing the number of records you pointed out (i.e. 1400*1400 ) then getting XML data and processing those might be a solution for you. I know it may not be the best solution but it will for sure address the low memory requirement that you have. Even POI site points this solution too:
"If memory footprint is an issue, then for XSSF, you can get at the underlying XML data, and process it yourself. This is intended for intermediate developers who are willing to learn a little bit of low level structure of .xlsx files, and who are happy processing XML in java. Its relatively simple to use, but requires a basic understanding of the file structure. The advantage provided is that you can read a XLSX file with a relatively small memory footprint."
source:http://poi.apache.org/spreadsheet/how-to.html

Reading e-mail attachments with Grooy/Grails + Javamail with a file size limit

I have a Groovy/Grails web app that reads e-mails from Gmail. It gets messages and attachments well, but I would like to limit the size of an attachment that I receive. Currently I have this code to read attachments:
byte[] file = new byte[maxSizeInBytes]
BufferedInputStream bis = new BufferedInputStream(part.getInputStream())
try {
file = bis.getBytes()
} catch (Exception e) {
...
}
The problem here is that Groovy simply expands the byte array to fit whatever comes in, so if my maxSizeInBytes is set to five megabytes (5*1024*1024), and I receive an attachment that is 10 megabytes the byte array simply expands to fit the entire file. How do I limit the size here? Even better, Is there a way to get how many bytes is the attachment before actually trying to download it?
Does part.inputStream.available() give you a resonable approximation?
Edit
Or, part.size probably gives you the encoded size of the attachment. I saw over here that multiplying this value by 0.65 should give you a rough approximation of the final attachment size

Resources