即時通訊使用mobitek GSM調制解調器和它使用的源代碼是在VB中。現在我想將代碼轉換爲C#。我遇到的代碼是intModemStatus = SMS.ModemInit(frmModem.txtPort.Text, "")
。在此之後,該代碼將與選擇的情況下經過如下:轉換vb代碼到C#
intModemStatus = SMS.ModemInit(frmModem.txtPort.Text, "")
Select Case intModemStatus
Case 0
FrmModem.txtText.Text = "GSM Modem Not Connected!"
'[VB - Module1] frmModem.txtText = "GSM Modem Not Connected!"
Exit Sub
Case 1
FrmModem.txtText.Text = "CONNECTED!"
'[VB - Module1] frmModem.txtText = "GSM Modem Connected!"
Exit Sub
Case 2
FrmModem.txtText.Text = "PIN Required!"
'[VB - Module1] frmModem.txtText = "PIN Required!"
Exit Sub
Case 3
FrmModem.txtText.Text = "Incorrect PIN Entered! Warning after 3 tries of incorrect PIN entered, your SIM card will be blocked by TELCO!"
'[VB - Module1] frmModem.txtText = "Incorrect PIN entered! Warning: after 3 tries of incorrect PIN entered, your SIM card will be blocked by TELCO!"
Exit Sub
Case 4
FrmModem.txtText.Text = "Your SIM card is blocked by TELCO!"
'[VB - Module1] frmModem.txtText = "Your SIM card is blocked by TELCO!"
Exit Sub
Case 5
FrmModem.txtText.Text = "Your SIM card has problem!"
'[VB - Module1] frmModem.txtText = "Your SIM card has problem!"
Exit Sub
Case Else
FrmModem.txtText.Text = "GSM Modem Not Connected!"
'[VB - Module1] frmModem.txtText = "GSM Modem Not Connected!"
Exit Sub
End Select
我已經轉換一切到C#包括與開關的情況下是這樣的:
int ModemStatus = sms.ModemInit(txtPort.Text, "");
switch (intModemStatus)
{
case 0:
txtText.Text = "GSM Modem Not Connected!";
//[VB - Module1] frmModem.txtText = "GSM Modem Not Connected!"
return;
break;
case 1:
txtText.Text = "CONNECTED!";
//[VB - Module1] frmModem.txtText = "GSM Modem Connected!"
return;
break;
case 2:
txtText.Text = "PIN Required!";
//[VB - Module1] frmModem.txtText = "PIN Required!"
return;
break;
case 3:
txtText.Text = "Incorrect PIN Entered! Warning after 3 tries of incorrect PIN entered, your SIM card will be blocked by TELCO!";
//[VB - Module1] frmModem.txtText = "Incorrect PIN entered! Warning: after 3 tries of incorrect PIN entered, your SIM card will be blocked by TELCO!"
return;
break;
case 4:
txtText.Text = "Your SIM card is blocked by TELCO!";
//[VB - Module1] frmModem.txtText = "Your SIM card is blocked by TELCO!"
return;
break;
case 5:
txtText.Text = "Your SIM card has problem!";
//[VB - Module1] frmModem.txtText = "Your SIM card has problem!"
return;
break;
default:
txtText.Text = "GSM Modem Not Connected!";
//[VB - Module1] frmModem.txtText = "GSM Modem Not Connected!"
return;
break;
}
不過,我有這樣的煩惱代碼int ModemStatus = sms.ModemInit(txtPort.Text, "");
。它說,
Argument 1cannot convert string to short. the best overloaded method match for mobitekSMSAPI5.ModemInit(short, string) have some invalid argument.
然後我試圖改變int ModemStatus = sms.ModemInit(txtPort.Text, "");
但它說相同。
使用mobitek gsm調制解調器,我需要添加MobitekSMSAPI5的參考,我做到了。交換機代碼將確定調制解調器是否已連接,否則。
我真的很希望有人能加緊解決這個問題。我卡在中間,我不知道從哪裏開始。任何形式的幫助表示讚賞。謝謝。
這裏是我的錯誤: 使用此代碼時出現IM:
short port;
if (!short.TryParse(txtPort.Text, out port))
{
throw new Exception("Failed to parse port");
// or any other handling - depends on your needs
}
int ModemStatus = sms.ModemInit(port, "");
現在它時,即時通訊改變如下面的代碼將出現不同的錯誤。
我終於明白了,非常感謝你!我真的很感激。再次感謝。 –
@sarabrown沒問題,很高興它幫助你:) – James