Skip to content

Commit

Permalink
成功读取IMSI,由于没有插卡,无法读取IMSI和ICCID
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Dec 25, 2023
1 parent a303e57 commit 6743d46
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
36 changes: 11 additions & 25 deletions SmartA2/Net/NetModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,49 +56,35 @@ public NetResult Send(UInt16 cmd, Byte[] args)
XTrace.WriteLine("=> {0}", data.ToHex("-"));
#endif

var rs = new Byte[1024];
if (_socket.Available > 0) _socket.Receive(rs);

_socket.Send(data);

var rs = new Byte[1024];
var count = _socket.Receive(rs);
if (count == 0) return null;

#if DEBUG
XTrace.WriteLine("<= {0}", rs.ToHex("-", 0, count));
#endif

var ms = new MemoryStream(rs);
var ms = new MemoryStream(rs, 0, count);
var reader = new Binary { Stream = ms, IsLittleEndian = false, EncodeInt = false, TrimZero = true };
if (reader.ReadFixedString(3) != "HTR") return null;

cmd = reader.ReadUInt16();
var result = reader.ReadUInt16();
var cmd2 = reader.ReadUInt16();
var code = reader.ReadUInt16();
var str = reader.ReadFixedString(-1);
//var dt = reader.ReadBytes(-1);
//var str = dt.ToStr();

////var len = -1;
////var buf = reader.ReadBytes(len);
////if (len < 0) len = buf.Length;

////// 剔除头尾非法字符
////Int32 s, e;
////for (s = 0; s < len && (buf[s] == 0x00 || buf[s] == 0xFF); s++) ;
////for (e = len - 1; e >= 0 && (buf[e] == 0x00 || buf[e] == 0xFF); e--) ;

////XTrace.WriteLine("s={0} e={1}", s, e);
////var str = buf.ToStr(null, s, e - s + 1);

//XTrace.WriteLine("cmd={0} result={1} str={2}", cmd, result, str);

return new NetResult { Cmd = cmd, Result = result, Message = str };
return new NetResult { Cmd = cmd2, Code = code, Message = str };
}
#endregion

#region 功能
public String GetInfo()
{
var rs = Send(51, new Byte[0]);
if (rs == null) return null;
if (rs == null || rs.Code != 0) return null;

return rs.Message;
}
Expand All @@ -119,12 +105,12 @@ public String GetIMSI()
return rs.Message;
}

public Int32 GetCSQ()
public String GetCSQ()
{
var rs = Send(102, new Byte[0]);
if (rs == null) return -1;
if (rs == null) return null;

return rs.Result;
return rs.Message;
}

public String GetCOPS()
Expand Down
2 changes: 1 addition & 1 deletion SmartA2/Net/NetResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class NetResult
{
public UInt16 Cmd { get; set; }

public UInt16 Result { get; set; }
public UInt16 Code { get; set; }

public String Message { get; set; }
}
20 changes: 17 additions & 3 deletions Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,28 @@ static void Test3()
module.Open();

XTrace.WriteLine("Info:\t{0}", module.GetInfo());

//Thread.Sleep(1000);
XTrace.WriteLine("Version:\t{0}", module.GetVersion());
//Thread.Sleep(1000);
XTrace.WriteLine("State:\t{0}", module.GetState());

//Thread.Sleep(1000);
XTrace.WriteLine("IMEI:\t{0}", module.GetIMEI());
//Thread.Sleep(1000);
XTrace.WriteLine("IMSI:\t{0}", module.GetIMSI());

//Thread.Sleep(1000);
XTrace.WriteLine("CSQ:\t{0}", module.GetCSQ());
//Thread.Sleep(1000);
XTrace.WriteLine("COPS:\t{0}", module.GetCOPS());

//Thread.Sleep(1000);
XTrace.WriteLine("ICCID:\t{0}", module.GetICCID());

//Thread.Sleep(1000);
XTrace.WriteLine("LACCI:\t{0}", module.GetLACCI());
XTrace.WriteLine("LBS:\t{0}", module.GetLBS());
XTrace.WriteLine("Version:\t{0}", module.GetVersion());
XTrace.WriteLine("State:\t{0}", module.GetState());

//Thread.Sleep(1000);
XTrace.WriteLine("LBS:\t{0}", module.GetLBS());
}

0 comments on commit 6743d46

Please sign in to comment.