我使用 mobitek gsm 调制解调器,它使用的源代码是在 VB 中。现在我想将代码转换为 c#。我遇到问题的代码是intModemStatus = SMS.ModemInit(frmModem.txtPort.Text, "")
。之后,代码将通过以下选择案例进行:
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, "");
。它说
参数 1 无法将字符串转换为短字符串。mobitekSMSAPI5.ModemInit(short, string) 的最佳重载方法匹配有一些无效参数。
然后我试图改变int ModemStatus = sms.ModemInit(txtPort.Text, "");
,但它说的一样。
要使用 mobitek gsm 调制解调器,我需要添加 MobitekSMSAPI5 的引用,我做到了。开关代码将确定调制解调器是否已连接。
我真的希望有人能加紧解决这个问题。我卡在中间,我不知道从哪里开始。任何形式的帮助表示赞赏。谢谢你。
这是我的错误:当我使用此代码时,它会出现:
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, "");
现在,当我像下面这样更改代码时,它会出现不同的错误。