天天看點

dicom網絡通訊入門(1)

看标準 越看越糊,根本原因:dicom抽象得非常嚴重,是“專家”弄的。沒辦法。

又是什麼服務類 又是什麼sop,相信你把dicom标準看到頭大 都不知如何下手。 不就是 socket麼 這有何難。 首先你得了解神馬叫pdu,從pdu入門 ,我隻能這麼說了。pdu就是pdu  protocol data unit   反正就是這麼個概念  你把它了解為socket資料包就行了。他的結構是開始1位元組是pdu類型 然後一位元組始終是0 ,然後是4位元組 表示資料長度 然後是指定長度的資料。

簡圖:

dicom網絡通訊入門(1)
然後專門為了 寫這個部落格 我弄了點 測試資料,都是二進制檔案
dicom網絡通訊入門(1)
dicom網絡通訊入門(1)
dicom網絡通訊入門(1)
好然後我們立馬來設計一個程式,立馬  ok 開搞:

1 namespace DcmEcho
 2 {
 3     class Program
 4     {
 5         static void Main(string[] args)
 6         {
 7             TcpClient client = new TcpClient();
 8             client.Connect("localhost", 104);
 9             NetworkStream stream= client.GetStream();
10 
11             byte[] data = dump(0);
12             byte[] data_res = new byte[1024];
13             uint len = 0;
14             stream.Write(data, 0, data.Length);
15             stream.Read(data_res, 0, 2);
16             stream.Read(data_res, 0, 4);
17             //注意此處是big位元組序要進行翻轉
18             Array.Reverse(data_res, 0, 4);
19             len = BitConverter.ToUInt32(data_res, 0);
20             stream.Read(data_res, 0, (int)len);
21 
22             data = dump(1);
23             stream.Write(data, 0, data.Length);
24             stream.Read(data_res, 0, 2);
25             stream.Read(data_res, 0, 4);
26             Array.Reverse(data_res, 0, 4);
27             len = BitConverter.ToUInt32(data_res, 0);
28             stream.Read(data_res, 0, (int)len);
29 
30             data = dump(2);
31             stream.Write(data, 0, data.Length);
32 
33             Console.ReadKey();
34         }
35 
36         static byte[] dump(int indx)
37         {
38             string[] datas = new string[3];
39             datas[0] = @"    01 00 00 00 00 CC 00 01 00 00 64 63 6D 70 72 69     
40 6E 74 65 72 00 00 00 00 00 00 64 63 6D 56 69 65 
41 77 65 72 00 00 00 00 00 00 00 00 00 00 00 00 00 
42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
43 00 00 00 00 00 00 00 00 00 00 10 00 00 15 31 2E 
44 32 2E 38 34 30 2E 31 30 30 30 38 2E 33 2E 31 2E 
45 31 2E 31 20 00 00 2E 01 00 00 00 30 00 00 11 31 
46 2E 32 2E 38 34 30 2E 31 30 30 30 38 2E 31 2E 31 
47 40 00 00 11 31 2E 32 2E 38 34 30 2E 31 30 30 30 
48 38 2E 31 2E 32 50 00 00 39 51 00 00 04 00 00 40 
49 00 52 00 00 1E 31 2E 32 2E 38 32 36 2E 30 2E 31 
50 2E 31 32 33 34 35 36 37 2E 32 2E 31 33 39 36 2E 
51 39 39 39 55 00 00 0B 41 53 53 41 53 53 4D 65 64 
52 69 63                                           
53 ";
54             datas[1] = @"    04 00 00 00 00 4A 00 00 00 46 01 03 00 00 00 00  
55 04 00 00 00 38 00 00 00 00 00 02 00 12 00 00 00 
56 31 2E 32 2E 38 34 30 2E 31 30 30 30 38 2E 31 2E 
57 31 00 00 00 00 01 02 00 00 00 30 00 00 00 10 01 
58 02 00 00 00 03 00 00 00 00 08 02 00 00 00 01 01 
59 ";
60             datas[2] = @" 05 00 00 00 00 04 00 00 00 00";
61 
62             datas[indx] = datas[indx].Trim().Replace(" ", "");
63             datas[indx] = datas[indx].Replace("\n", "");
64             datas[indx] = datas[indx].Replace("\r", "");
65 
66             byte[] data = new byte[datas[indx].Length / 2];
67             for (int i = 0; i < data.Length; i++)
68             {
69                 data[i] = (byte)Convert.ToInt32(datas[indx].Substring(i * 2, 2), 16);
70             }
71             return data;
72         }
73     }
74 }      

好 我們來測試下,我們始終都用這個程式進行測試:http://www.mrxstudio.com/ 也是由本人編寫。

喏 ,echo響應測試成功:

dicom網絡通訊入門(1)

了解這些了,然後呢 你不可能 每次别人來都把這一坨屎一樣的東西塞給别人吧,參數不一樣 請求的各種執行個體uid  dimse指令 和資料都不一樣,不會報錯麼 這是dicom協定 程式 不是普通的socket程式,雖然都是基于socket的。明白你要做什麼了吧,坦白的說沒什麼技術含量 但這卻是一個相當大的工程 并且要心細慢慢來。這是整個從協商連接配接 到列印完成要經過的步驟流程圖:

dicom網絡通訊入門(1)