📄 mingxi.cpp
字号:
{
MessageBox(L"请先选择菜!");
return;
}
i=m_list.GetNextSelectedItem(pos);
m_liushuihao=m_list.GetItemText(i,11);
m_xuhao=m_list.GetItemText(i,1);
m_caipubianhao=m_list.GetItemText(i,10);
WideCharToMultiByte(CP_ACP,0,m_liushuihao,-1,liushuihao,10,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_xuhao,-1,xuhao,4,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_caipubianhao,-1,caipubianhao,10,NULL,NULL);
sprintf(sendbuf,"%c%s%c%s%c%s%c%s%c",0x0d,liushuihao,0x1b,xuhao,0x1b,caipubianhao,0x1b,oprid,0x1b);
crc=0;
sendlen=strlen(sendbuf);
i=0;
while (i<sendlen)
{
crc+=(unsigned char)sendbuf[i];
i++;
}
sendbuf[i]=crc/256;
sendbuf[i+1]=crc%256;
sendbuf[i+2]=0;
sendlen+=3;
s_sock = socket (AF_INET, SOCK_STREAM, 0);
if (s_sock == INVALID_SOCKET)
{
MessageBox(TEXT("通讯失败,请检查设备"));
return;
}
addrClient.sin_family=AF_INET;
addrClient.sin_addr.s_addr=SAddr;
addrClient.sin_port=portid;
if (connect(s_sock, (struct sockaddr *)&addrClient, sizeof (addrClient))==SOCKET_ERROR )
{
closesocket(s_sock);
MessageBox(TEXT("通讯失败,请检查设备"));
return;
}
i=0;
while (i<5)
{
i++;
if (send (s_sock, sendbuf, sendlen, 0) == SOCKET_ERROR)
{
continue;
}
if ((nCnt=recv (s_sock, recbuf, 256, 0)) == SOCKET_ERROR)
{
continue;
}
crc=0;
j=0;
while (j<nCnt-3)
{
crc+=(unsigned char)recbuf[j];
j++;
}
if (crc!=(unsigned char)recbuf[j]*256+(unsigned char)recbuf[j+1]) continue;
if (recbuf[1]==0x01) continue;
if (recbuf[1]==0x03)
{
closesocket(s_sock);
MessageBox(TEXT("叫起失败!"));
return;
}
closesocket(s_sock);
MessageBox(TEXT("叫起成功!"));
return;
}
closesocket(s_sock);
MessageBox(TEXT("通讯失败,请检查设备"));
return;
}
void CMingxi::OnButtonShanchu()
{
SOCKET s_sock;
struct sockaddr_in addrClient;
int nCnt,i,j,sendlen;
char sendbuf[257],recbuf[257];
unsigned short crc;
u_short portid;
u_long SAddr;
int taiweilen,caipulen;
char oprid[21],caipubianhao[11],xuhao[5],liushuihao[11],shuliang[11],beizhu[51];
CString strCode1,strCode2;
char RecordBuf[257],*ptchar,field[257];
HANDLE hFile;
unsigned long len;
WCHAR wcCode[257];
POSITION pos= m_list.GetFirstSelectedItemPosition();
if (pos==NULL)
{
MessageBox(L"请先选择菜!");
return;
}
i=m_list.GetNextSelectedItem(pos);
strCode1=m_list.GetItemText(i,0);
m_liushuihao=m_list.GetItemText(i,11);
m_xuhao=m_list.GetItemText(i,1);
m_caipubianhao=m_list.GetItemText(i,10);
m_shuliang=m_list.GetItemText(i,3);
m_beizhu=m_list.GetItemText(i,6);
if (strCode1.Compare(L"*"))
{
hFile = CreateFile(m_taihao, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile==INVALID_HANDLE_VALUE) return;
while(fGetRecord(hFile,RecordBuf))
{
ptchar=RecordBuf+1;
ptchar=fGetField(ptchar,field,1);
MultiByteToWideChar(CP_ACP,0,field,-1,wcCode,255);
if (RecordBuf[0]=='n'&&!m_xuhao.Compare(wcCode))
{
SetFilePointer(hFile,-2-strlen(RecordBuf),0,FILE_CURRENT);
WriteFile(hFile,"y",1,&len,NULL);
break;
}
}
CloseHandle(hFile);
UpData();
return;
}
hFile = CreateFile(CONFIGFILE, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile==INVALID_HANDLE_VALUE)
{
MessageBox(TEXT("打开配置文件失败,请点“配置”按钮重新配置"));
return;
}
ReadFile(hFile,&SAddr,4,&len,NULL);
ReadFile(hFile,&portid,2,&len,NULL);
ReadFile(hFile,&taiweilen,4,&len,NULL);
ReadFile(hFile,&caipulen,4,&len,NULL);
ReadFile(hFile,oprid,20,&len,NULL);
CloseHandle(hFile);
WideCharToMultiByte(CP_ACP,0,m_liushuihao,-1,liushuihao,10,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_xuhao,-1,xuhao,4,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_caipubianhao,-1,caipubianhao,10,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_shuliang,-1,shuliang,10,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_beizhu,-1,beizhu,51,NULL,NULL);
sprintf(sendbuf,"%c%s%c%s%c%s%c%s%c%s%c%s%c",0x0b,liushuihao,0x1b,xuhao,0x1b,caipubianhao,0x1b,shuliang,0x1b,beizhu,0x1b,oprid,0x1b);
crc=0;
sendlen=strlen(sendbuf);
i=0;
while (i<sendlen)
{
crc+=(unsigned char)sendbuf[i];
i++;
}
sendbuf[i]=crc/256;
sendbuf[i+1]=crc%256;
sendbuf[i+2]=0;
sendlen+=3;
s_sock = socket (AF_INET, SOCK_STREAM, 0);
if (s_sock == INVALID_SOCKET)
{
MessageBox(TEXT("通讯失败,请检查设备"));
return;
}
addrClient.sin_family=AF_INET;
addrClient.sin_addr.s_addr=SAddr;
addrClient.sin_port=portid;
if (connect(s_sock, (struct sockaddr *)&addrClient, sizeof (addrClient))==SOCKET_ERROR )
{
closesocket(s_sock);
MessageBox(TEXT("通讯失败,请检查设备"));
return;
}
//MultiByteToWideChar(CP_ACP,WC_DEFAULTCHAR,sendbuf,-1,wcCode,0);
//MessageBox(wcCode);
i=0;
while (i<5)
{
i++;
if (send (s_sock, sendbuf, sendlen, 0) == SOCKET_ERROR)
{
continue;
}
if ((nCnt=recv (s_sock, recbuf, 256, 0)) == SOCKET_ERROR)
{
continue;
}
crc=0;
j=0;
while (j<nCnt-3)
{
crc+=(unsigned char)recbuf[j];
j++;
}
if (crc!=(unsigned char)recbuf[j]*256+(unsigned char)recbuf[j+1]) continue;
if (recbuf[1]==0x01) continue;
if (recbuf[1]==0x03)
{
closesocket(s_sock);
MessageBox(TEXT("退菜失败!"));
return;
}
closesocket(s_sock);
hFile = CreateFile(m_taihao, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile==INVALID_HANDLE_VALUE) return;
while(fGetRecord(hFile,RecordBuf))
{
ptchar=RecordBuf+1;
ptchar=fGetField(ptchar,field,1);
MultiByteToWideChar(CP_ACP,0,field,-1,wcCode,255);
if (RecordBuf[0]=='n'&&!m_xuhao.Compare(wcCode))
{
SetFilePointer(hFile,-2-strlen(RecordBuf),0,FILE_CURRENT);
WriteFile(hFile,"y",1,&len,NULL);
break;
}
}
CloseHandle(hFile);
UpData();
MessageBox(TEXT("退菜成功!"));
return;
}
closesocket(s_sock);
MessageBox(TEXT("通讯失败,请检查设备"));
return;
}
void CMingxi::OnButtonChuicai()
{
SOCKET s_sock;
struct sockaddr_in addrClient;
int nCnt,i,j,sendlen;
char sendbuf[257],recbuf[257];
unsigned short crc;
u_short portid;
u_long SAddr;
int taiweilen,caipulen;
char oprid[21],caipubianhao[11],xuhao[5],liushuihao[11];
HANDLE hFile;
unsigned long len;
hFile = CreateFile(CONFIGFILE, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile==INVALID_HANDLE_VALUE)
{
MessageBox(TEXT("打开配置文件失败,请点“配置”按钮重新配置"));
return;
}
ReadFile(hFile,&SAddr,4,&len,NULL);
ReadFile(hFile,&portid,2,&len,NULL);
ReadFile(hFile,&taiweilen,4,&len,NULL);
ReadFile(hFile,&caipulen,4,&len,NULL);
ReadFile(hFile,oprid,20,&len,NULL);
CloseHandle(hFile);
POSITION pos= m_list.GetFirstSelectedItemPosition();
if (pos==NULL)
{
MessageBox(L"请先选择菜!");
return;
}
i=m_list.GetNextSelectedItem(pos);
m_liushuihao=m_list.GetItemText(i,11);
m_xuhao=m_list.GetItemText(i,1);
m_caipubianhao=m_list.GetItemText(i,10);
WideCharToMultiByte(CP_ACP,0,m_liushuihao,-1,liushuihao,10,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_xuhao,-1,xuhao,4,NULL,NULL);
WideCharToMultiByte(CP_ACP,0,m_caipubianhao,-1,caipubianhao,10,NULL,NULL);
sprintf(sendbuf,"%c%s%c%s%c%s%c%s%c",0x11,liushuihao,0x1b,xuhao,0x1b,caipubianhao,0x1b,oprid,0x1b);
crc=0;
sendlen=strlen(sendbuf);
i=0;
while (i<sendlen)
{
crc+=(unsigned char)sendbuf[i];
i++;
}
sendbuf[i]=crc/256;
sendbuf[i+1]=crc%256;
sendbuf[i+2]=0;
sendlen+=3;
s_sock = socket (AF_INET, SOCK_STREAM, 0);
if (s_sock == INVALID_SOCKET)
{
MessageBox(TEXT("通讯失败,请检查设备"));
return;
}
addrClient.sin_family=AF_INET;
addrClient.sin_addr.s_addr=SAddr;
addrClient.sin_port=portid;
if (connect(s_sock, (struct sockaddr *)&addrClient, sizeof (addrClient))==SOCKET_ERROR )
{
closesocket(s_sock);
MessageBox(TEXT("通讯失败,请检查设备"));
return;
}
i=0;
while (i<5)
{
i++;
if (send (s_sock, sendbuf, sendlen, 0) == SOCKET_ERROR)
{
continue;
}
if ((nCnt=recv (s_sock, recbuf, 256, 0)) == SOCKET_ERROR)
{
continue;
}
crc=0;
j=0;
while (j<nCnt-3)
{
crc+=(unsigned char)recbuf[j];
j++;
}
if (crc!=(unsigned char)recbuf[j]*256+(unsigned char)recbuf[j+1]) continue;
if (recbuf[1]==0x01) continue;
if (recbuf[1]==0x03)
{
closesocket(s_sock);
MessageBox(TEXT("催菜失败!"));
return;
}
closesocket(s_sock);
MessageBox(TEXT("催菜成功!"));
return;
}
closesocket(s_sock);
MessageBox(TEXT("通讯失败,请检查设备"));
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -