问题描述
是电脑与某种机器通讯的,厂家只有delphi的例程,但我没有学过delphi,有哪位热心的朋友帮我改写成C#的代码:如果分不够,可以另开帖赠送,先谢了!//初始化IP机procedureTfrmRealInfo.pdIPSocket;vari:Integer;beginConnCount:=0;SockCount:=0;//ifchkServer.Checkedthenbeginsrvrsckt1.Port:=sePort.Value;srvrsckt1.Active:=Trueendelsebegin//每台IP机都必须初始化,并且保存返回的句柄SetLength(A_Sock,chkListMoc.Items.Count);fori:=0tochkListMoc.Items.Count-1dobeginifnotchkListMoc.Checked[i]thencontinue;SockCount:=SockCount+1;SetLength(SockArray,SockCount);trypdGetPort(chkListMoc.Items[i]);SockArray[SockCount-1]:=TClientSocket.Create(Nil);SockArray[SockCount-1].Active:=False;SockArray[SockCount-1].Port:=1024;SockArray[SockCount-1].Host:=fip;SockArray[SockCount-1].OnRead:=CsockRead;SockArray[SockCount-1].OnError:=CsockError;SockArray[SockCount-1].OnConnect:=CSockConnect;//ClientRBuf[SockCount-1].Ip:=fip;ClientRBuf[SockCount-1].RBuf:=nil;//SockArray[SockCount-1].Active:=True;exceptShowMessage(fip+'--Communicationcannotopen!');end;end;end;end;//读取IP机传来的数据信息procedureTfrmRealInfo.pdServerRead_New(Socket:TCustomWinSocket);varstrTime,CardNo:string;TempBuf0:array[0..100]ofByte;TempBuf:TByteDynArray;Recs,i,OldLen:integer;iCard:Int64;Y,M,D,H,Min:Word;ClientI:Integer;beginedt2.Text:=Socket.RemoteAddress;ClientI:=fnFindClient(Socket.RemoteAddress);ifClientI=-1thenExit;//接收数据包并累加到缓冲区内Recs:=Socket.ReceiveBuf(TempBuf0,Socket.ReceiveLength);OldLen:=High(ClientRbuf[ClientI].Rbuf);SetLength(ClientRbuf[ClientI].Rbuf,OldLen+1+Recs);fori:=0toRecs-1doClientRbuf[ClientI].Rbuf[OldLen+1+i]:=TempBuf0[i];//ifHigh(ClientRbuf[ClientI].Rbuf)>=24thenTempBuf:=fnGetOneCMD(ClientI);//ifHigh(TempBuf)<>7thenExit;//iCard:=TempBuf[0]*65536*256+TempBuf[1]*256*256+TempBuf[2]*256+TempBuf[3];CardNo:=IntToStr(iCard);//CardNo:=stringofchar('0',KHCD-length(CardNo))+CardNo;//分解日期Y:=((TempBuf[4]shr2)and$3F)+2000;M:=((TempBuf[4]and$3)shl2)or(TempBuf[5]shr6);D:=(TempBuf[5]shr1)and$1F;H:=((TempBuf[5]and$1)shl4)or((TempBuf[6]shr4)and$F);Min:=((TempBuf[7]shr6)and$3)or((TempBuf[6]and$f)shl2);strTime:=IntToStr(Y);ifM<9thenstrTime:=strTime+'-0'+inttostr(M)elsestrTime:=strTime+'-'+inttostr(M);ifD<9thenstrTime:=strTime+'-0'+inttostr(D)elsestrTime:=strTime+'-'+inttostr(D);strTime:=strTime+'';ifH<9thenstrTime:=strTime+'0'+inttostr(H)elsestrTime:=strTime+''+inttostr(H);ifMin<9thenstrTime:=strTime+':0'+inttostr(Min)elsestrTime:=strTime+':'+inttostr(Min);//ifCardNo=edt1.TextthenExit;edt1.Text:=CardNo;edt3.Text:=strTime;GetUserInfo(CardNo);//pdDoCMD(CardNo,strTime);end;
解决方案
解决方案二:
首先去了解c#的socket,然后对着代码调一下,SetLength是对数组设置长度厂家的一些dll,你需要用dllImport引入其他感觉没啥,语法都差不多
解决方案三:
解决方案四:
直接给你改造,愿意做的人少。你自己试着去改造一下,不明白的在问吧。