请各位帮忙看看一下代码: 加粗红色部分代码在asp.net(c#)中该如何操作?我不了解PHP的语言。还望各位指点。谢谢!<?php
// reader for panel monitors
$fp = fopen("http://192.168.0.xxx","r");
$mysqli = new mysqli("$server",$username,$password,$mysolar);
[color=#FF0000]while ($line = fgets($fp,32)) {
$line = str_replace("","",trim($line));
$key = substr($line,0,1);[/color]switch ($key) {
  case 3:
    // things to do
  break;
  case 4:
    // things to do
  break;
  case 5:
    // this is light from LED recorded as is
    $val = (int) substr($line,4);
    $sql = "insert into readings values(NULL,NULL,$key,$val)";
    $result = $mysqli->query($sql);
    //echo "val = $val\n";
  break;
  case 6:
    // temperature from a TMP36 attached to back of solar cell
    $val = (int) substr($line,4);
    $tmp = degc($val); // convert to Celsius/Centigrade
    $tmp -= 5; // calibration
    $sql = "insert into readings values(NULL,NULL,$key,$tmp)";
    $result = $mysqli->query($sql);
  break;
  default:
    //echo "Found strange key $key!\n";
  break;
}
function degc($v) {
$t = $v * (5/1024);
$t -= 0.5;
$t *= 100;
return round($t,1);
?>

解决方案 »

  1.   

    open() 函数打开文件或者 URL。
    如果打开失败返回 FALSE。
    参数r表示以只读方式打开
      

  2.   


    private byte[] GetWebDataFromUrl(string url)
        {
            try
            {
                System.Net.WebClient wc = new System.Net.WebClient();
                byte[] data = wc.DownloadData(url);
                wc.Dispose();
                return data;
            }
            catch
            {
                return null;
            }
        }
      

  3.   

    楼主真厉害,上次我也是把php该asp.net 弄得我一身汗
      

  4.   


    运行代码,得到的结果为:System.byte[]; 
    怎得不到数据传递的参数呢?
      

  5.   

    用Response.BinaryWrite()输出全部数据到页面,或者用File.WriteAllBytes()写入文件,再或者用Encoding.GetString()转换为字符串。总之要用操作byte[]的方法来输出,就看你具体的需求是什么了。
      

  6.   

    谢谢btman52的帮助,得到了想要的结果。