Click here to Skip to main content
11,706,799 members (52,905 online)
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 20:28pm
mehdi_k865
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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I'm getting the same problem. Have you solved it?
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 140
1 OriginalGriff 125
2 chainerlt 110
3 ppolymorphe 99
4 Mika Wendelius 70
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,487
2 CPallini 5,189
3 Maciej Los 4,766
4 Mika Wendelius 3,696


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 30 Jun 2015
Copyright © CodeProject, 1999-2015
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