Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
So I'm using the SerialPort class to read data from a serial device. my code is as shown below. I researched a little and found out that serial data is read at 100kb/sec. So according to that, my program would have to read the data in just 2 seconds since I have called the readHexString function with 200000 as a parameter and it thus reads 200000 bytes, I just want to know why it takes many minutes to read the data serially?
serialPort.openPort();
serialPort.setParams(SerialPort.BAUDRATE_57600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
int count = 0;
String data = serialPort.readHexString(200000);
You can not assume 100kb/sec
That leads to 34,722 seconds for 2000000 Bytes
I'd like to ask if your device is sending continuously Data? Your Code reads 200.000 Bytes. So you have to wait until the Buffer is full. You could try to cycle smaller amount of data and break if a marker is reached.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am making an android app where i should send camera frames via udp/tcp socket
I get each frame as a byte[] array in a FrameCallback
Then i used the socket to send each time MAX_BUFFER_SIZE bytes from the array
as fragments.
But it's not Effcient enough since the array size sent is about 10M, and there will be alot of buffering when the stream will be desplayed.
I can't compress the array too since it's an OMEGA(n) operation, SO
First of all , what protocol is better for this problem? UDP, TCP ?
And in general , how can i send that huge array over socket in a video streaming efficiency level ?
I solved it by using the UDP Protocol
And used Allocation class to compress the data array, it did the work!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Lets say I have a file with the size of 1mb. Now I do following:
FileOutputStream fos = new FileOutputStream(file);
fos.write(new byte[0]);
fos.close();
When I write a empty byte array to a file, what happens with the "removed" bytes? Do they still exist on the file system? Are they still somehow connected to file (e.g. flagged)? Does this make a difference than just deleting the file?
Thanks.
From the Java point of view data which were in the file before the write call are simply gone. On most operating systems calling this write method will actually result in the file been open for writing, which in turn (in the case the file already exists) truncates the file. As for the underlying storage itself this will disassociate storage blocks (sectors, clusters, extends...) from the file itself marking them free. On a traditional hard-drive, the data itself might be recoverable, but on a flash based storage the information of the block been marked free is actualy delivered to the chip too (TRIM) and data are virtually gone for good.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am reading from a file which contains several lines of string. I am checking the strings, line by line vs a predefined value. My concern in the required time which is so high. I was thinking of copying the file's content in a local string value and continue with this variable instead of reading from a file. is it going to change the performance of the code?
You should read by line. Use BufferedReader or Scanner then performance will be the same as reading full file. But if you read full file you are limited with file size, it simply may not fit in memory
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Bluetooth SPP is sending data from AnalogReadSerial.ino of Arduino to my Android Phone. Those Value will be used to display using GaugeView.
Use this:
String myString;
void setup()
{
Serial.begin(300);
//Sets the data rate in bits per second (baud) for serial data transmission. For communicating with the computer, use one of these rates: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200.
//You can, however, specify other rates - for example, to communicate over pins 0 and 1 with a component that requires a particular baud rate.
}
void loop()
{
while (Serial.available())
{
myString = Serial.readString();
//the rest of the code..
}
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to create a server which receives both text and image. For text I used DataInputStream dis.readUTF(), and for image, I used ObjectInputStream ois.readObject() to read the image as byte[]. So how can I write code to detect the data receiving is text or byte[]?
You'll have to use some kind of signal from the client to know whether it is sending text or an image.
Alternatively, you could receive on different ports depending on the type of input.