C/C++ :: How To Completely Send A String Through Serial Port
May 9, 2013
I am doing a messaging application using Visual C++ window form application.
Sometimes I can't receive a whole message from the sender. If i type short sentence like "123456", it can be shown properly. But, if i type a quite long sentence like "123456789123456789", it can't shown a correct message, can't show exactly the whole message.
here is my code:
//transmission:
String^ message;
String^ message1;
String^ name = this->serialPort1->PortName;
[Code].....
View 1 Replies
ADVERTISEMENT
Jul 17, 2013
I am trying to write data in Russian language to the serial (RS-232) port. My display device is already set to that character code page.
But output on the device is not exactly what I require.
My code snippet is like this below
CString pBuffer = L"английский"; //Russian Language
LPBYTE pByte = new BYTE[pBuffer.GetLength() + 1];
memcpy(pByte, (VOID*)LPCTSTR(pBuffer), pBuffer.GetLength());
long nBuffer=pBuffer.GetLength()+1;
DWORD dwWritten=0;
WriteFile(pHandle , pByte, nBuffer ,&dwWritten , NULL);
pHandle is a valid handle.
View 4 Replies
View Related
Aug 13, 2014
private void button1_Click(object sender, EventArgs e) {
serialPort1.PortName = "COM1";
serialPort1.BaudRate = 9600;
serialPort1.DataBits = 8;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
[Code]...
In my project i have a serialport control and a button, there is no error but i want to know how actually this works, i want to send and recieve the data from the serial port don't know how to do it..
View 9 Replies
View Related
Sep 3, 2014
i want to read the string plus image from serialport.
sample output:
DENOMI Ver SERIAL NUMBER
100 V <<<<IMAGE>>>>
100 N <<<<IMAGE>>>>
but when im trying to receive the data and using serialPort.ReadExisting();
this is the output:
DENOMI Ver SERIAL NUMBER
100 V *!???????q??q??y??y?y?q?????????xxxxppppp????y?py?`q??q??q? q???????????????8?p8?@8??8?????????????8??8?p8?p?p??p??p?????????q?q?p8p88?p8?????????????8?p8?p8?p8?p8??8??x??x8?8?8??p?p??p??p0?py?p????????~8?q??q??q??p8?????p??????????????????????????????p8?x?x<?x<?x<??<?????
View 1 Replies
View Related
Dec 17, 2013
I am trying to convert decimal value 1 to 32 to hex value and insert it at 4th pos of char array and send it as hex value at the serial port .
My issue is it is converting to decimal to hex value but when it sends, it treat the converted hex value as char and sends it equivalent hex value.
For example
if decimal =1 then its hex = 1.
so , writebuffer[3] =1
But when we send whole writebuffer through send function, it treat this 1 as char and sends its hex value as 31. how to send its hex value.
unsigned int i=0;
char hex[3];
unsigned char hexunsigned[3];
unsigned int dec;
do {
unsigned char writebuffer[8] ={0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
[Code] ....
The send function is
void serial::send(unsigned char data[], DWORD noOfByte) {
DWORD dwBytesWrite;
WriteFile(serialHandle, data, noOfByte, &dwBytesWrite, NULL);
}
View 2 Replies
View Related
Apr 14, 2014
I am using libserial library to communicate through the serial port in c++. the linux cpu is communicating with a modem through the serial port. basically this is what i want to do
Code:
//I want:
cpu to write command_1 to modem
Wait for the answer from modem
read serial port
check if command successful (i.e modem sends OK if successful and ERROR if there is an error)
If there is an error, resend command_1
if successful then Write command_2 to modem Wait for answer read again serial port check if command is succesful (modem again sends OK if successful and ERROR if there is an error) basically, this is the code...
Code:
serial_port <<command_1 <<'
'; //send 1st command
sleep(2); //delay a while
[Code].....
View 6 Replies
View Related
Mar 6, 2015
I have a Voltage Range from -10V up to +10V, which I transform to a voltage Range 0V to 5V, with the schematic i've attached, so I can use the A/D converter of my ATMEGA32 processor.
Now I'd like to write the value of the Input Voltage (which moves in the Range of -10V to + 10V) on the serial port, but i don't know how i should calculate this factor. At the moment, I can only write the value of the A/D Converter Input on the serial, but this is only 0V to 5V...
View 2 Replies
View Related
Dec 29, 2013
Explain me a working code to read and write a file using serial communication.and i need to store that file.I know normal file handling in C, but how it is through serial port i am not getting.
View 1 Replies
View Related
Jun 2, 2010
How can i read barcode scanner value from serial port?
View 5 Replies
View Related
Feb 17, 2013
I want to read and write value on serail port to Microcontroller with MFC. The MFC have no serial port tool like in VB Professionnal edition. I try to find MFC connect serial port example but I not found. If you have good example for read and write on serial port with MFC
View 2 Replies
View Related
Mar 8, 2014
i have problem i make code that take data from serial com port for weighting machine it is ok working but it recieve data in more lines.I try to make it receive data in one line In code below i need to take weight fro weight bridge machine automatically by timer in visual studio 2005.it works but receive weight values in more lines. I need to receive weight in one line and automatically updated then convert t to integer
void Application_Idle(object sender, EventArgs e)
{
label3.Text = serialPort1.IsOpen ? "[Open]" : "[Closed]";
}
[Code].....
View 3 Replies
View Related
May 10, 2014
I am making a MFC application with VC++2012 with receiving data from Serial Port and the data is stored in a Listbox, then after processing (convert into numbers) and get these data to draw a sine wave on the chart. (I intend to make a virtual oscilloscope).
Everything works ok at the beginning, but after receiving about 300 items or above (in the Listbox) the value seem stucking (or lagging) and work very slowly.
I receive data by the SerialPort_DataReceived() method, and process of converting and drawing chart also in this method, I think this makes the system overload!!
View 1 Replies
View Related
Feb 26, 2013
I need to send a packet of type byte:
0x00, 0x01, 0x02, 0x11, 0x00, 0x00
to a device via the serial port and then I receive and store data coming from device like this:
0x01, 0x01, 0x01 , 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x01, 0x00.
Writing lines of code through which:
1) I create the array
2) the sending the array to serial port
3) I'll see what I'm sending
4) I get the data
I'm using Visual Studio 2010 and C + + or VC++ language.
View 14 Replies
View Related
Jun 27, 2014
I am using libserial library to interact with a modem using c++. The C++ code sends an AT command:
Code:
my_serial_stream << "AT+CSQ" << '
' ;
The modem responds with a response, either ERROR or OK, The c++ code to read the response:
Code:
while( serial_port.rdbuf()->in_avail() > 0 )
{
char next_byte;
serial_port.get(next_byte);
std::cerr << std::hex << (int)next_byte << " ";
}
std::cerr << std::endl;
I would like to handle the response such that if the response is OK, the modem sends another command and if the response is ERROR, the modem resends the first command.
View 1 Replies
View Related
Feb 26, 2013
I am writing a code using Visual C++ to access serial port.
Code:
HANDLE hSerial= CreateFile(L"COM1", GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
DCB dcb = {0};
dcb.DCBlength=sizeof(dcbSerialParams);
dcb.BaudRate=CBR_1200;
dcb.ByteSize=8;
dcb.StopBits=ONESTOPBIT;
dcb.Parity=NOPARITY;
I am getting error in all last five lines in above code at dcb. and error is give below:-
Error: this declaration has no storage class or type specifier
View 2 Replies
View Related
Aug 18, 2014
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.IO.Ports;
[Code] ....
How to pick date / time when serial port starts reading , and also when reading stops ?
View 2 Replies
View Related
Jul 30, 2014
I have a class which I wrote and one of its object is "SerialPort" .NET class. In my MainWindow I created instance of my class called "SerialPortComm", then I send through some functions of mine, commands to the Serial Port, and I receive answers through "DataReceived" event.
But when I trying to use Dispatcher.BeginInvoke to write my data I have received (successfully), nothing shows on the RichTextBox which I'm trying to write to.
What can caused that, and How I can make it works?
SerialPortComm.cs
public partial class SerialPortComm : UserControl {
public SerialPort mySerialPort = new SerialPort();
public void Open_Port(string comNumber, int baudRate) {
mySerialPort.PortName = comNumber;
mySerialPort.BaudRate = baudRate;
[Code] ....
View 7 Replies
View Related
Apr 1, 2014
i developed 2programm that the first one is in C and the second one is in c#.and now i have to send some string text from c to c#.how can i do that in c ?
View 8 Replies
View Related
Apr 8, 2014
I have a function which send a string as argument to a txt file, like the following:
void Fprint(... ofstream& myfile, const string a, const int b)
......
myfile << "name: " << a << " age:" << b << "" << endl;
......
}
However, my IDE (msvc12.0) popup an error about the << before a, by citing "No operator matches these operands.
View 2 Replies
View Related
Feb 5, 2014
I'm looking to code a completely random distribution of numbers that doesn't affect performance using rand. I believe this code would be ideal but I don't understand how to use it. Where would I input the range of numbers and the quantity?
double uniform_deviate ( int seed ){
return seed * ( 1.0 / ( RAND_MAX + 1.0 ) );
} int r = M + uniform_deviate ( rand() ) * ( N - M );
And for the seed...
unsigned time_seed(){
time_t now = time ( 0 );
unsigned char *p = (unsigned char *)&now;
unsigned seed = 0;
size_t i;
for ( i = 0; i < sizeof now; i++ )
seed = seed * ( UCHAR_MAX + 2U ) + p[i];
return seed;
} srand ( time_seed() );
View 2 Replies
View Related
Sep 17, 2014
For example, I have a game loading to start up .. How can I check if it completely loaded?
View 1 Replies
View Related
Jan 13, 2014
In my program I have to load a page in a second window based on user's decision. This is how I do it:
case 1:
Page1 p1 = new Page1();
secondwindow.frame.Source = new Uri("p1.xaml", UriKind.Relative);
secondwindow.Show();
break;
case 2:
Page2 p2 = new Page2();
secondwindow.frame.Source = new Uri("p2.xaml", UriKind.Relative);
secondwindow.Show();
break;
The user should not be able to navigate between these two pages, and between choosing one or the other page, the user will have some interaction with the main window. For the user interaction with the main window, the second window gets hidden:
if (secondWindow != null)
{
secondwindow.Hide();
}
Now if the user selects the first page and and then the second page, when I show the second window, I can see the first page for a fraction of a second, and then second page gets rendered. I wanted to know if there is a way to make sure the rendering is complete before using:
secondwindow.Show();
View 5 Replies
View Related
Oct 18, 2014
I read correctly in MatLab some data by serial port of a device, but in C... nothing.
Code: #include <cstdlib>
#include <stdio.h>
int main(void)
{
FILE *in;
char linha[30];
while(1)
{
// Abrir porta COM de onde se ligou a placa
in = fopen( "COM8", "r" );
if( in == NULL )
{
[code].....
The message "ERRO: no consigo abrir porta COM " don't appear, so I haven't error there. I just do not see anything in the terminal.
View 3 Replies
View Related
Dec 18, 2013
I have to communicate between two laptops using USB-to-Serial adapter. I have written 2 programs one for sending and another for receiving. Programs were written in both C and C# programming languages.
Using C language: I am able to successfully communicate using C-Programs mentioned below. But the problem is speed. It takes around 1 hour(60min) for just to pass 150MB. improving the performance of this programs...I also mention some comments along with programs for self understanding.Sender File on laptop with serial port :
Code:
#include <stdio.h>
#include <bios.h>
#include <conio.h>
}
[code]....
The above 4 programs behaves as, sender send a character and receives an ack for every character. I have followed this approach, bcoz other approaches were not working fine (in the sense the complete data is not sent, the amount of data sent is not judgeable, bcoz it will different every tym). when i used this approach it worked fine.
View 6 Replies
View Related
Jan 27, 2013
I'm new in c programming and my requirement is as follows. I make a code for oss mixer and now when new systems, throwing the OSS, and there is no /dev/mixer I want to port my code to alsa but my skills are minimal.
Code:
static int mixer_fd = -1, mixer_src = -1;
static char *devices[] = SOUND_DEVICE_NAMES;
int mixer_init(char *mixer_device, char *mixer_source) {
int i;
mixer_src = -1;
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
if (strcmp(mixer_source, devices[i]) == 0)
[Code] ....
Coexistance with OSS would be nice, so both could be used depending on users choice. Perhaps: if this first
part of the mixer name is a valid device file, try OSS, otherwise try ALSA?
View 1 Replies
View Related
Jan 24, 2012
I'm creating a small port scanning app which use a port range defined by user.My problem with the code is that I find it not efficient enough meaning that it ping very slow, especially when ports are not responding meaning that I must wait for the timeout before continuing to next port.
I want to make this small app threaded. The problem here is that I'm kind of blank of how to implement threading in my program. This is my code which is a method which does the actual checking, the other part of the code is a simple button with for loop for advancing my port number.
Code:
private void ScanPort(IPAddress address, int port) {
using (TcpClient client = new TcpClient() {
IAsyncResult result = client.BeginConnect(address, port, null, null);
if (result.AsyncWaitHandle.WaitOne((int)nudTimeout.Value, false)) txtDisplay.AppendText("Port: " + port + " is open." + Environment.NewLine);
else txtDisplay.AppendText("Port: " + port + " is closed." + Environment.NewLine);
} }
I have read some basic threading tutorial but I just don't know how to implement this piece of code so I can check ports much faster.
View 3 Replies
View Related