Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ USB
Hello,
I've been trying to send a command from my c++ program to epos2 70/10 through RS232 (not using the DLL provided), but I only receive two 79 witch is 'O' meaning ok, but after that I receive nothing, and the the motor doesn't work(not spining). What's wrong?
please help.
Here is my code:
 
#include "stdafx.h"
#include<iostream>
using namespace std;
using namespace System::IO::Ports;
using namespace System;
 
typedef unsigned char byte;
 
int main()
{
	SerialPort^ sp=gcnew SerialPort("COM1",115200);
	
	sp->Open();
	if(sp->IsOpen)
		cout<<"port opened."<<endl;
 
	array<byte>^bytes = gcnew array<byte>(8);
 
	bytes[0]=0x10;
	bytes[1]=0x01;
	bytes[2]=0x03;
	bytes[3]=0x20;
	bytes[4]=0x01;
	bytes[5]=0x02;
	bytes[6]=0x88;
	bytes[7]=0xA8;
 
	sp->Write(bytes, 0, 8);
	cout<<sp->ReadByte()<<"first\n";
	cout<<sp->ReadByte()<<"second\n";
	cout<<sp->ReadByte()<<"third\n";
	//cout<<s<<"\n";

    return 0;
}
Posted 14-Apr-13 21:28pm
mehdi_k844

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It seems that your program exits after reading bytes from the device. Should epos2 70/10 continue to run even after your program exits? I mean what does command you're sending tell epos2 70/10, To 'spin regardless app is running' or 'spin till app is running'?
 
If it does mean something like 'spin till app is running', try putting getch() before return 0;
  Permalink  
Comments
mehdi_k at 15-Apr-13 2:54am
   
EPOS2 should return 2 bytes witch are 97 or 'O', that it returns it, but after that it should return another bytes sp->ReadByte()<<"third\n"; that it doesn't and stucks. the command I found in an example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 310
1 OriginalGriff 285
2 Afzaal Ahmad Zeeshan 200
3 Sergey Alexandrovich Kryukov 195
4 BillWoodruff 180
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 20 Jun 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100