Reputation: 1
I want to convert my C# code to Delphi.
I am trying to send messages to a bank card terminal (speed point). Please assist. I have one of this MagIC3 devices. When I send messages over socket using C# I get my messages to the device successfully. On the other hand with Delphi its just quiet.
Here's is my C# Code:
public void CardRead
{
try
{
string length;
String szData = "E0940|" + sessionID + "|00|" + "Please Swip Card|";
length = szData.Length.ToString();
while (length.Length < 6)
{
length = "0" + length;
}
szData = length + szData;
byte[] byData = System.Text.Encoding.ASCII.GetBytes(szData);
socClient.Send(byData);
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
}
Problem is my Delphi code:
procedure TForm1.CardRead;
var
wInt :Integer;
wLength, szData :String;
wData :TBytes;
begin
try
szData := 'E0940|' + sessionID + '|00|' + 'Please Swipe Card|';
wLength := IntToStr(Length(szData));
While (Length(wLength) < 6) do
begin
wLength := '0' + wLength;
end;
szData := wLength + szData;
wData := TEncoding.ASCII.GetBytes(szData);
socClient.IOHandler.WriteBufferOpen;
for wInt := 0 to Length(wData) do
begin
socClient.Socket.WriteLn;
end;
socClient.Socket.WriteLn;
socClient.Socket.WriteBufferClose;
except
socClient.Socket.WriteBufferCancel;
raise;
end;
end;
Upvotes: 0
Views: 289
Reputation: 75
Assuming you are using Indy sockets you need to use the Write
procedure instead of the Writeln
( it only writes a new line). So something like this
soClient.Socket.Write(wData)
should do the trick. Note that you are opening the buffer of the IOHandler
and then using the socket instead. I suppose you need to open the socket buffer. And don't forget to WriteBufferFlush
the socket so no data stays in the buffer.
Upvotes: 1