20,11 → 20,42 |
|
cConnection::cConnection() |
{ |
i_Type = 0; |
|
TTY = new ManageSerialPort(); |
|
TTY->setBaudRate(BAUD57600); //BaudRate |
TTY->setDataBits(DATA_8); //DataBits |
TTY->setParity(PAR_NONE); //Parity |
TTY->setStopBits(STOP_1); //StopBits |
TTY->setFlowControl(FLOW_OFF); //FlowControl |
|
TTY->setTimeout(0, 10); |
TTY->enableSending(); |
TTY->enableReceiving(); |
|
b_isOpen = false; |
} |
|
void cConnection::new_Data(QString Data) |
{ |
while ((RxData.String.length() > 1) && (RxData.String.at(1) == '#')) |
{ |
RxData.String.remove(0,1); |
} |
|
if (ToolBox::check_CRC(RxData.String)) |
{ |
RxData.Input = RxData.String.toLatin1().data(); |
emit(newData(RxData)); |
} |
else |
{ |
emit(showTerminal(2, RxData.String)); |
} |
|
} |
|
void cConnection::slot_newDataReceived(const QByteArray &dataReceived) |
{ |
const char *RXt; |
35,21 → 66,7 |
{ |
if (RXt[a] == '\r') |
{ |
while ((RxData.String.length() > 1) && (RxData.String.at(1) == '#')) |
{ |
RxData.String.remove(0,1); |
} |
|
if (ToolBox::check_CRC(RxData.String)) |
{ |
RxData.Input = RxData.String.toLatin1().data(); |
emit(newData(RxData)); |
// emit(showTerminal(1, RxData.String)); |
} |
else |
{ |
emit(showTerminal(2, RxData.String)); |
} |
new_Data(QString("")); |
RxData.String = QString(""); |
} |
else |
67,44 → 84,107 |
|
bool cConnection::Close() |
{ |
TTY->close(); |
switch(i_Type) |
{ |
case C_TTY : |
{ |
TTY->close(); |
|
disconnect(TTY, SIGNAL(newDataReceived(const QByteArray &)), this, 0); |
disconnect(TTY, SIGNAL(newDataReceived(const QByteArray &)), this, 0); |
|
b_isOpen = false; |
b_isOpen = false; |
} |
break; |
case C_IP : |
{ |
TcpSocket->disconnectFromHost(); |
disconnect(TcpSocket, SIGNAL(connected()), 0, 0); |
disconnect(TcpSocket, SIGNAL(readyRead()), 0, 0); |
disconnect(TcpSocket, SIGNAL(disconnected()), 0, 0); |
|
b_isOpen = false; |
} |
break; |
} |
|
return b_isOpen; |
} |
|
bool cConnection::Open(QString Address) |
bool cConnection::Open(int Typ, QString Address) |
{ |
TTY->setPort(Address); //Port |
switch(Typ) |
{ |
case C_TTY : |
{ |
TTY->setPort(Address); //Port |
TTY->open(); |
|
TTY->setBaudRate(BAUD57600); //BaudRate |
TTY->setDataBits(DATA_8); //DataBits |
TTY->setParity(PAR_NONE); //Parity |
TTY->setStopBits(STOP_1); //StopBits |
TTY->setFlowControl(FLOW_OFF); //FlowControl |
ToolBox::Wait(1000); |
|
TTY->setTimeout(0, 10); |
TTY->enableSending(); |
TTY->enableReceiving(); |
if (TTY->isOpen()) |
{ |
connect(TTY, SIGNAL(newDataReceived(const QByteArray &)), this, SLOT(slot_newDataReceived(const QByteArray &))); |
|
TTY->open(); |
ToolBox::Wait(1000); |
qDebug("Try Open"); |
if (TTY->isOpen()) |
{ |
qDebug("Opend"); |
connect(TTY, SIGNAL(newDataReceived(const QByteArray &)), this, SLOT(slot_newDataReceived(const QByteArray &))); |
TTY->receiveData(); |
b_isOpen = true; |
i_Type = C_TTY; |
} |
} |
break; |
case C_IP : |
{ |
QStringList Host = Address.split(":"); |
|
TTY->receiveData(); |
b_isOpen = true; |
TcpSocket = new(QTcpSocket); |
TcpSocket->connectToHost (Host[1], Host[2].toInt()); |
|
connect(TcpSocket, SIGNAL(connected()), this, SLOT(slot_IP_Connected()) ); |
// connect(TcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_Error(QAbstractSocket::SocketError))); |
b_isOpen = true; |
i_Type = C_IP; |
} |
break; |
} |
|
return b_isOpen; |
} |
|
void cConnection::slot_IP_Connected() |
{ |
connect(TcpSocket, SIGNAL(readyRead()), SLOT(slot_IP_ReadLine())); |
connect(TcpSocket, SIGNAL(disconnected()),TcpSocket, SLOT(deleteLater())); |
connect(TcpSocket, SIGNAL(disconnected()),this, SLOT(slot_IP_Disconnect())); |
|
// emit sig_Connected(); |
} |
|
void cConnection::slot_IP_Disconnect() |
{ |
disconnect(TcpSocket, SIGNAL(disconnected()), 0, 0); |
disconnect(TcpSocket, SIGNAL(readyRead()), 0, 0); |
// emit sig_Disconnected(1); |
} |
|
void cConnection::slot_IP_ReadLine() |
{ |
QString Input = QString(TcpSocket->readLine(TcpSocket->bytesAvailable())).remove(QChar(' ')); |
|
int Len = Input.length(); |
|
for (int z = 0; z < Len; z++) |
{ |
if (Input[z] == '\r') |
{ |
new_Data(QString("")); |
RxData.String = QString(""); |
} |
else |
{ |
RxData.String = RxData.String + Input[z]; |
} |
} |
} |
|
bool cConnection::send_Cmd(char CMD, int Address, char Data[150],unsigned int Length, bool Resend) |
{ |
if (b_isOpen) |
134,7 → 214,19 |
} |
} |
|
TTY->sendData(Temp); |
switch(i_Type) |
{ |
case C_TTY : |
{ |
TTY->sendData(Temp); |
} |
break; |
case C_IP : |
{ |
TcpSocket->write(Temp); |
} |
break; |
} |
|
emit(showTerminal(3, TX_Data)); |
} |